I use google-play-services 8.1.0 (but it was tested on 7.8.0 as well). I create AdMob interstitial with this code:
_interstitialAd = new InterstitialAd(this);
_interstitialAd.setAdUnitId(getString(R.string.interstitial_admob));
_interstitialAd.setAdListener(new AdListener() {
#Override
public void onAdClosed() {
Logger.log("onAdClosed");
requestNewInterstitial();
}
public void onAdFailedToLoad(int errorCode) {
Logger.log("onAdFailedToLoad");
}
public void onAdLeftApplication() {
Logger.log("onAdLeftApplication");
}
public void onAdOpened() {
Logger.log("onAdOpened");
}
public void onAdLoaded() {
Logger.log("onAdLoaded");
}
});
requestNewInterstitial();
After some user actions I call
if (_interstitialAd.isLoaded()) {
_interstitialAd.show();
return;
}
But it takes some time before ad is shown. I've added some log messages and they show that ad is loaded onAdLoaded is called.
I measured delay before ad display and each time it's different. On Nexus 5 (marshmallow) it's from 100ms, which is good to 1500ms which is not good, but comfortable. But on other devices such Nexus 7 (2012) and Nexus 10 it's varies from 4s, to even 6s which is awful.
Also I got issue which messed up my fragments lifecycle. And I had to change fragments pop from backstack and this helps (I don't remove fragments before ads show but do this after onAdClosed), but this steps doesn't remove delay before ad display.
All this steps were done on 8.3.0 as well
Can anybody helps me to remove this delay?
I noticed this with some ads this week. It seems they are serving a new type of interstitial that is causing this delay, because it never happened before. I temporarily disabled text and image ads (because video ads seem to work well) until it's fixed.
You don't quantify what delay you are experiencing. So it is very hard to answer this question. But if the ad has already been downloaded before you call show() then the only delay will be rendering, which is impacted by the hardware you run on and the other processing that you are doing at the time.
Related
I try to show Unity Ads rewarded placement through mediation on Android device, i figured out that its working on android 8 but when i test it on android 9 then UnityAds.isReady() always returns false.
this is the latest mediation gradle configuration.
implementation 'com.google.ads.mediation:unity:3.4.6.0'
this is my configuration code
//UnityAds.initialize(AdTask.this, AdConfig.UNITY_AD_GAME_ID, unityAdsListener,true);//this approach is depecated
UnityAds.initialize(AdTask.this,AdConfig.UNITY_AD_GAME_ID,true);
UnityAds.isInitialized(); // just to making sure that its been initialized
UnityAdsImplementation.addListener(unityAdsListener);
this is how i try to show the ad
if (UnityAds.isReady(AdConfig.UNITY_AD_NEW_TASK_PLACEMENT_ID)) {
UnityAds.show(AdTask.this, AdConfig.UNITY_AD_NEW_TASK_PLACEMENT_ID);
}
and this is my listener class
private class UnityAdsListener implements IUnityAdsListener {
#Override
public void onUnityAdsReady (String placementId) {
// Implement functionality for an ad being ready to show.
}
#Override
public void onUnityAdsStart (String placementId) {
// Implement functionality for a user starting to watch an ad.
}
#Override
public void onUnityAdsFinish (String placementId, UnityAds.FinishState finishState) {
// Implement functionality for a user finishing an ad.
Log.d("unityad","finished");
}
#Override
public void onUnityAdsError (UnityAds.UnityAdsError error, String message) {
// Implement functionality for a Unity Ads service error occurring.
Log.d("ERROR","zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"+message);
}
}
i debugged each steps and found that unity ad gets initialized but ad is not ready to be shown.
log has no clue what is happening therefore i am not sharing the logcat. if any of you have experienced this before then i would love to know how you handled this.
I don't know if it's related, But I'm currently working on my game and ads were working fine, today (like 1 hour ago) i tested my game and the ads were not ready no matter what.. perhaps it's a problem with Google ads?
During testing of my application, I noticed that I very frequently get ERROR_CODE_NO_FILL for Interstitial Ad. I think that the same situation with real ads might be one of the causes of low income from the application, so I want to increase the rate of showed ads. As the solution, I decided to make requests until I will get some app, so it might take from 5 to 50 requests until I will get out of onAdFailedToLoad. Is it a legitimate way to do this? Won't I get banned by AdMob with such way of getting more ads?
That's what I do in setAdListener in onCreate:
#Override
public void onAdFailedToLoad(int errorCode) {
requestNewInterstitial();
}
And requestNewInterstitial():
private void requestNewInterstitial() {
AdRequest adRequest = new AdRequest.Builder()
.build();
mInterstitialAd.loadAd(adRequest);
}
No, you won't get banned...
You can do this, but don't show the Ad as soon it is loaded, this will be a bombarding of Ads & user won't like that...
private void showInterstitialadd() {
mInterstitialAd = new InterstitialAd(MainActivity.this);
// set the ad unit ID
mInterstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));
AdRequest adRequest = new AdRequest.Builder()
.build();
// Load ads into Interstitial Ads
mInterstitialAd.loadAd(adRequest);
mInterstitialAd.setAdListener(new AdListener() {
public void onAdLoaded() {
showInterstitial();
}
});
}
private void showInterstitial() {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}
I am using the above function for showing Ads....and its working absolutely fine on my test device but when I remove that .addTestdevice().....and run on any other devices it does not shows up....
There may be no issue in your code but AdMob doesn't show ads on real device quickly. You have to wait for few days. Before that, you have to enter some details like address and payment account detail in your AdMob account.
Don't worry they guide via email.
After you enter details, wait for few days, you will be notified in AdMob account that ads are showing.
In my case, it takes 2 days and, only Banner and Interstitial ads were activated at that time and video ads still do not get loaded.
So if ads are showing on test device then it will also be showing in the real device. The only thing you have to do is complete AdMob account setup and wait.
Also, don't forget to remove .addTestdevice() code before checking on real device.
I did some testing with ads on my device and then pushed app to the play with with production unit ID. After a while when the version was available on play I deleted the debug build from my device and installed from playstore .
The code is same as what developer site suggests
mInterstitialAd = new InterstitialAd(callerActivity);
mInterstitialAd.setAdUnitId(callerActivity.getString(R.string.interstitial_ad_unit_id));
AdRequest adRequest = new AdRequest.Builder().build();
mInterstitialAd.loadAd(adRequest);
if (mInterstitialAd.isLoaded()) {
Log.i(TAG," Interstitial Add :Loaded");
mInterstitialAd.show();
}
else {
Log.i(TAG,"Could not load Interstitial Add");
}
But surprisingly I see following in logs
2:38.743 16617-16617/com.osfg.tictactoe I/Ads﹕ Starting ad request.
06-17 18:22:38.743 16617-16617/com.osfg.tictactoe I/Ads﹕ Use AdRequest.Builder.addTestDevice("235F7FAA8F49FF2CAA1DD2FAFE6B9E8A") to get test ads on this device.
06-17 18:22:40.529 16617-16617/com.osfg.tictactoe I/GamePlayOnClickListener﹕ Game Over. Some player won
06-17 18:22:43.551 16617-16617/com.osfg.tictactoe I/GamePlayOnClickListener﹕ Could not load Interstitial Add
06-17 18:22:43.551 16617-16617/com.osfg.tictactoe I/GamePlayOnClickListener﹕ Resetting game
It is still using my device as test device? Not sure what is happening here. Anyone has any prior experience on this? I know it calculates the hash but does it store it on admob server but again this is client call. How would it know? I am confused. Any suggestion is appreciated.
Most likely you're encountering this issue because mInterstitialAd.loadAd(adRequest); is calling a background thread to load a new ad, but you're checking to see if the ad has been loaded immediately. You don't give that background thread a chance to connect to the server, get the ad, etc.
To fix this, you need to place your code for when the ad has been loaded inside an AdListener, like so:
mInterstitialAd.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
Log.i(TAG," Interstitial Add :Loaded");
}
#Override
public void onAdFailedToLoad(int error) {
Log.i(TAG,"Could not load Interstitial Add");
}
}
mInterstitialAd.loadAd(adRequest);
The if statement if (mInterstitialAd.isLoaded()) is for checking at a later time if the ad has been loaded, such as after the user does some action. Not when an activity begins or anything similar.
In my app I put Interstitial full page ad. And it is working fine on most phones but when I checked in my friends Galaxy Note 1 the Interstitial ad is repeating and reating. I don't know why it is happening in one mobile phone only.. I checked with more than three other mobile phoe including Samsung Galaxy S2, S3 etc... but in those phones there was no problem and I tested in Emulator also.. there was no problem once i closed the Ad it will not repeat. The problem is with this particular phone , if anybody knows the reason please help... Is this the problem with memory or somethiing ..
I am giving the code below.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.tabpmnth_xm);
// Create the interstitial.
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("ca-app-pub-xxxxxxxxxxxx8x/x2xxxxxxxx");
// Create ad request.
AdRequest aadRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("xxxxxxxxxxxxxxxxxxxx")
.build();
// Begin loading your interstitial.
interstitial.loadAd(aadRequest);
interstitial.setAdListener(new AdListener(){
public void onAdLoaded(){
displayInterstitial();
}
});
public void displayInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
Sorry Jocheved for the late replay. If this problem is not happening in every phone it could possibly the problem is in that user's mobile settings. Just check whether in his/her " settings > Developer Options > Do not keep activities " selected or not. If it is selected then the app will destroy every activities as soon as the user left the current activity. So when an interstitial is displayed , the current activity will be normally in onPause. but it will be destroyed and when the user close the interstitial and come back again oncreate will run and the ad will display. To avoid this situation you can inform the user to check whether the option is selected or not.. or otherwise u may need to find some other solution and solve it through programming. thanks..
https://groups.google.com/forum/#!topic/google-admob-ads-sdk/i6zOe2Hy-xc
Check out above link where Google admob engineer has explained why this issue is arising for you. Don't need to include displayInterstitial() inside onAdLoaded(). Either you want to display your interstitial after some time, I use onCountdownTimer() myself to achieve this. For e.g. showing an Ad after 5 seconds.
new CountDownTimer(5000, 5) {
#Override
public void onTick(long millisUntilFinished) {
}
#Override
public void onFinish() {
displayInterstitial();
}
}.start();