I am trying to load interstitial advertisements for my app. Whenever I try to load these ads I get a Error saying "No Ads Config" from Domain "com.google.android.gms.ads".
Here is the code:
My AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ayush.torch">
<application
android:allowBackup="true"
android:icon="@drawable/ic_ico"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".main">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="i_have_put_my_app_id_here"/>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
</manifest>
onCreate() in main.java
// Creating the InterstitialAd and setting the adUnitId.
interstitialAd = new InterstitialAd(this);
interstitialAd.setAdUnitId("i have also put my interstitial ad id here");
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
Toast.makeText(main.this, "Ad Loaded", Toast.LENGTH_SHORT).show();
}
@Override
public void onAdFailedToLoad(LoadAdError loadAdError) {
String error = String.format("domain: %s, code: %d, message: %s", loadAdError.getDomain(), loadAdError.getCode(), loadAdError.getMessage());
Toast.makeText(main.this, "onAdFailedToLoad() with error: " + error, Toast.LENGTH_SHORT).show();
}
});
When I load my ad in a on function it gives me error "No Ad Config."
Log.d("[Ads]","Ad Load State For on(): " + interstitialAd.isLoaded());
if (interstitialAd.isLoaded())
{
interstitialAd.show();
}
Fixed It and it works.
Found a resource from google. And It cleared all my doubts. For Test Ad Resource Click Me
The Advertisement works in two ways.
Scenario 1: While the App Is In Devlopment
For this case, we need to use Test Advertisements. Admob and "com.google.android.gms.ads" doesnt allow user to use Advertisements in Development Phase due to false impressions.
To enable Test Advertisement. There are two ways: You can either use google ad unit id's which are available on the link adove. Or You can use your own ad unit id, but you will be needing to register your device as a test device and use your own request configuration. Here is a simple Example: Search for your "Device Id" In "Logcat"
It will look something like
I/ADS: Use Requested Configuration......Arrays.asList("Your device Id will be here");
Then Just Copy Paste This(i can read your mind..)
// Change your Id
RequestConfiguration configuration = new RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("your device id should go here")).build();
MobileAds.setRequestConfiguration(configuration);
Now just load the ad and it will pop up. Congratz. :)
Scenario 2: While the App Is In Production
This is pretty simple part...