I'm trying to implement Google Admob into my app but the test banner isn't even displaying. I've managed to get rid of all debug error messages but still get nothing being display. Could it be hiding in the background? This code is implemented in my OnCreate method after OpenGL initialization. Have followed the guides on Google to the letter. I'm stumped.
MobileAds.initialize(this, new OnInitializationCompleteListener() {
#Override
public void onInitializationComplete(InitializationStatus initializationStatus){}
});
List<String> testDeviceIds = Arrays.asList("8X126XD7X13XD3X8CXE0X2BXA1X67XDX");
RequestConfiguration requestConfiguration
= new RequestConfiguration.Builder()
.setTestDeviceIds(testDeviceIds)
.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_G)
.build();
MobileAds.setRequestConfiguration(requestConfiguration);
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111"); // ANDROID TEST ID
AdRequest adrequest = new AdRequest.Builder().build();
adView.loadAd(adrequest);
I've run adrequest.isTestDevice(this) and it comes back as TRUE so my device seems to be working. I'm testing on a real device (Sony Xperia XZ). Any ideas??
Related
I'm trying to implement NativeAd in my app.
Everything worked fine until yesterday, it's now printing these error logs.
I/Ads: WebView loading for native ads.
I/Ads: Javascript has loaded for native ads.
I/Ads: Received log message: <Google:HTML> Incorrect native ad response. Click actions were not properly specified
onAdFailedToLoad errorCode = 0
So I can't show native ads anymore.
Here's how I do the requests.
private AdRequest adRequest = new AdRequest.Builder()
.build();
private NativeAdOptions nativeAdOptions = new NativeAdOptions.Builder()
.setAdChoicesPlacement(ADCHOICES_TOP_RIGHT)
.setRequestMultipleImages(false)
.setReturnUrlsForImageAssets(true)
// Methods in the NativeAdOptions.Builder class can be
// used here to specify individual options settings.
.build();
AdLoader adLoader = new AdLoader.Builder(mContext, adUnitId)
.forAppInstallAd(new NativeAppInstallAd.OnAppInstallAdLoadedListener() {
#Override
public void onAppInstallAdLoaded(NativeAppInstallAd appInstallAd) {
refreshAd(appInstallAd);
}
})
.forContentAd(new NativeContentAd.OnContentAdLoadedListener() {
#Override
public void onContentAdLoaded(NativeContentAd contentAd) {
refreshAd(contentAd);
}
})
.withAdListener(adListener)
.withNativeAdOptions(nativeAdOptions)
.build();
adLoader.loadAd(adRequest);
If I comment out forAppInstallAd then the ads can be downloaded again. But the fill rate is very low.
It looks like the SDK is rejecting the response sent down from the AdMob server, which is really weird. I don't think this is an issue that can be solved on StackOverflow, so I'd recommend creating a post in AdMob's SDK support forum, where the support team can try to dig into the issue.
My doubt is not weather its ok to click on live ads during development.I did all the formalities to get my admob ad working . Then i saw that we should only use test add during development . so i used this code:
AdRequest request = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // All emulators
.addTestDevice("AC98C820A50B4AD8A2106EDE96FB87D4") // An example device ID
.build();
It worked fine. But then i change i back to the live ad code fearing that i would forget to do so later:
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
But now the ad wont appear during test run. Is that normal?
will the ad work when i finally launch the app?
I dont see anything wrong with your code, but something similar happened to me when implementing admob too.
I didnt have in count that the ad must be loaded before showing it, and that the loading may take some time. If you try to show an ad that its not loaded, a black activity might be shown.
You should implement some waiting time or a listener in order to be sure that the add is loaded before showing it.
public InterstitialAd interstitialAd;
[...]
public void setNewInterstitialRequest()
{
interstitialAd = new InterstitialAd(CurrActivity.this);
interstitialAd.setAdUnitId("ca-app-pub-***************************");
AdRequest adRequest = new AdRequest.Builder()
//.addTestDevice("ZY22247DJV")
.build();
// Begin loading your interstitial.
interstitialAd.loadAd(adRequest);
//add listener so you know is fully loaded
interstitialAd.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
[...] // <- code you want to execute as soon as the ad is loaded
}
});
}
public void displayAd() {
try {
//verify is loaded before showing a black screen
if (interstitialAd.isLoaded()) {
interstitialAd.show();
}
//else
// showToast("Not loaded");
}
catch (Exception ex){}
}
So taking this in mind, if you want for the ad to be shown inmediately when something happens, you should have it loaded before that event occurs.
My banner adview showing correctly on real device and emulator. But interstilialad now showing real device although it showing correctly on emulator.
Every thing is okey for me. But i didn't understand why not showing.
EzFullScreenAds.class
public class EzFullScreenAds {
InterstitialAd mInterstitialAd;
Context context;
public EzFullScreenAds(Context context) { //constructor
this.context = context;
mInterstitialAd = new InterstitialAd(context);
mInterstitialAd.setAdUnitId(context.getString(R.string.adv_fullscreen));
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
mInterstitialAd.loadAd(adRequest);
mInterstitialAd.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
super.onAdLoaded();
if (mInterstitialAd.isLoaded()) mInterstitialAd.show();
}
});
}
}
That is usage it.
new EzFullScreenAds(MainActivity.this);
May be because it cannot fill.
To show test ad on real device you must add real test device ID. AdRequest.DEVICE_ID_EMULATOR only work on emulator.
The Mobile Ads SDK uses the tag "Ads" when writing to logcat. You can
filter for that tag in Android Studio's logcat viewer, which makes it
easier to find your device's ID.
More information here:
https://firebase.google.com/docs/admob/android/targeting#adrequest
You did not add your device number as a test device.
The way you this is:
AdRequest request = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // All emulators
.addTestDevice("A1124HIDFBIUBQWASFDSAFD") // This is what is missing
.build();
The way how you can find your number is once you have the admob SDK installed(as you already have) You run the emulater and inside the log (that you can find in your working enviroment) press "ctrl + f" and search for "device".
Good Luck
public void adShow() {
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-581420244534656/2222222");
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
requestNewInterstitial();
reseter();
}
mInterstitialAd.setAdListener(new AdListener() {
#Override
public void onAdClosed() {
requestNewInterstitial();
reseter();
}
});
}
private void requestNewInterstitial() {
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("3D9834hiqewuiry48937498urequE")
.build();
mInterstitialAd.loadAd(adRequest);
}
}
I have tested the use of interstitial in my app using the default ad from google and it's working but now what must i do to make sure that the default orange ad is not displayed to users when I publish my app? I already have the AdUnitId.
So long as you have set a valid Ad unit id from the ad provider you're using, you should get real ads. The reason you most likely aren't seeing real ads is because of the line .addTestDevice("3D9834hiqewuiry48937498urequE") which basically says "Only show me the default orange ad on this device".
So, if you always test your app on the same device, this line is disabling real ads from appearing while you test (which is what you want). But this line will only disable real ads on a single device, the one you're using. On other devices, users will see real ads.
I've been working on this code where apparently the interstitial and banner ads keep failing to load.
Here's the code for creating the banner adview and adding the newly generated ad units. Also the code for interstitial ads which is supported with an adlistener to see if the ads work..
//Ads ----------------
// Create the adView
RelativeLayout layout = new RelativeLayout(this);
layout.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
//<!-- Ads Using Google Play Services SDK -->
adView = new AdView(this);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId(AD_UNIT_ID);
// Add the adView to it
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
params.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
adView.setLayoutParams(params);
layout.addView(mGLSurfaceView);
layout.addView(adView);
setContentView(layout);
//New AdRequest
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
//-----------------------------------------------------Interstitial Add
// Create an Interstitial ad.
interstitialAd = new InterstitialAd(this);
interstitialAd.setAdUnitId(AD_INTERSTITIAL_UNIT_ID);
interstitialAd.loadAd(new AdRequest.Builder().build());
interstitialAd.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
interstitialAd.show();
}
#Override
public void onAdFailedToLoad(int errorCode) {
Toast.makeText(getApplicationContext(), "Interstitial Ads loading failed", Toast.LENGTH_SHORT).show();
}
});
// Load the interstitial ad.
showInterstitialAds();
public void showInterstitialAds()
{
runOnUiThread(new Runnable() {
public void run() {
AdRequest interstitialAdRequest = new AdRequest.Builder().build();
interstitialAd.loadAd(interstitialAdRequest);
}
});
}
In the app, all I get is the Toast message declaring that the interstitial ads don't work. Even the banner ads don't work.
On the logcat, I get different messages:
I last got:
01-17 16:54:05.765: I/Ads(1136): No fill from ad server.
01-17 16:54:05.769: I/Ads(1136): Scheduling ad refresh 60000 milliseconds from now.
01-17 16:54:05.769: W/Ads(1136): Failed to load ad: 3
and there's this:
01-17 16:52:02.945: I/Ads(1136): Starting ad request.
01-17 16:52:02.945: I/Ads(1136): Use AdRequest.Builder.addTestDevice("A55B0AA295150C0583B3FADA0B02054B") to get test ads on this device.
I tried the above in the showInterstitialAds but I kept receiving that same error and ads didn't show.
Also, the most interesting one is:
There was a problem getting an ad response. ErrorCode: 2
With different numbers on the errocode: 0,2,3. I'm not sure what it means as I'm new to the whole android world (I just started coding a few months ago.)
Banner ads aren't loading because there are no ads available. That's what "No fill from ad server means". It happens occasionally especially when your traffic is low.
To test you should be configuring your AdView to show test ads.
See https://developer.android.com/reference/com/google/android/gms/ads/AdRequest.Builder.html#addTestDevice(java.lang.String)
Hard to say what is going wrong with your interstitial.
Are you using the correct AdUnitId?
Also never call interstitial#show() from onAdLoaded(). It' provides a very bad user experience and will probably get your account banned.
Instead you should call interstial#show() from a natural break point in your app, like at the end of a game level.