Android Interstitial ad repeating - android

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();

Related

Can I request new ad from onAdFailedToLoad?

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...

Admob live ads not showing in my application,while testing ads showing

Admob Live ads are not showing, while testing ads are showing. Live ads are not showing at all, I don't know what i am missing.
Here is code.
String.java XML
<!-- Insert Id admob -->
<string name="BannerAd_unit_id">cca-app-pub-1154915214031679/2100011458</string>
<string name="InterstitialAd_unit_id">ca-app-pub-1154915214031679/9049914448</string>
MainGame.Java Class
this.BANNER_AD_UNIT_ID = getResources().getString(R.string.BannerAd_unit_id);
showBanner();
screen java.class
public void showBanner() {
//banner ad
if (BANNER_AD_UNIT_ID.length() > 0) {
// Create an ad.
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(BANNER_AD_UNIT_ID);
//make ad visible on bottom of screen
RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
params1.addRule(RelativeLayout.CENTER_HORIZONTAL);
adView.setLayoutParams(params1);
layout.addView(adView);
// Create an ad request. Check logcat output for the hashed device ID to
// get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
//.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
//.addTestDevice("C01834A0B4A8FA4C03A0E09605F43819")//GalaxyS4*/
.build();
// Start loading the ad in the background.
adView.loadAd(adRequest);
}
}
If I Remove comment ".addTestDevice" Then testing ads are showing, if I comment it then live ads not showing. I don't know what is going on, any help will be appreciated.
If you're not receiving real ads, but are receiving 'test ads' then the implementation should be ok.
If you just created the ad account, it takes a few hours until real ads will appear and sometimes there might be no adds available to show.
Set an adListener to your adView and see what you're getting back. It might be a ERROR_CODE_NO_FILL or it might give you other hints to solve the problem.
Make sure you have updated AdMob with your payment details (go to Payments Section for that).
Check your AdMob dashboard to see the status of your ads to check if they are active.
Verify you used the correct Ad Unit Id.
After you update your info, it may take up to 24 hours to verify your information. After verification, they will enable your ad serving. You will get an email notification saying your ads are now being served.
If the test ads are working fine then your implementation is correct, but there is an option of "Payment" in the admob account which you need to fill. After filling up that form you will receive an email regarding the confirmation of payment details and message indicating that whether your information was accepted by the admob team or not if yes then your live ads will be showing up. But keep in mind that for the first few time the ad won't show up. it takes time to appear after the approval as well.
Here is the code snippet for the error code to find what is going wrong
mAdView = (com.google.android.gms.ads.AdView) findViewById(R.id.adView);
mAdView.setAdListener(new com.google.android.gms.ads.AdListener() {
#Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
Toast.makeText(HomeActivity.this, "onAdLoaded", Toast.LENGTH_SHORT).show();
}
#Override
public void onAdFailedToLoad(int errorCode) {
if(errorCode==AdRequest.ERROR_CODE_INTERNAL_ERROR)
Toast.makeText(HomeActivity.this, "onAdFailedToLoad", Toast.LENGTH_SHORT).show();
// Code to be executed when an ad request fails.
}
#Override
public void onAdOpened() {
Toast.makeText(HomeActivity.this, "onAdOpened", Toast.LENGTH_SHORT).show();
}
#Override
public void onAdLeftApplication() {
Toast.makeText(HomeActivity.this, "onAdLeftApplication", Toast.LENGTH_SHORT).show();
}
#Override
public void onAdClosed() {
Toast.makeText(HomeActivity.this, "onAdClosed", Toast.LENGTH_SHORT).show();
}
})
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
Get the error code:
ERROR_CODE_INTERNAL_ERROR - Something happened internally; for instance, an invalid response was received from the ad server.
ERROR_CODE_INVALID_REQUEST - The ad request was invalid; for instance, the ad unit ID was incorrect.
ERROR_CODE_NETWORK_ERROR - The ad request was unsuccessful due to network connectivity.
ERROR_CODE_NO_FILL - The ad request was successful, but no ad was returned due to lack of ad inventory.

Admob Not showing ads on real devices only showing on Test devices only

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.

Interstitial ad is displayed with delay

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.

Forcing admob to refresh ad every second in Android

I have built an android app which has a fixed screen that will remain focused for more than a minute. Kind of a story in the page.
I have integrated Admob adrequest into the application. But it is the single ad that comes on load of the screen and remains till I quit.
Can I do something so that the Ad will change every 1 sec.
You can control the refresh frequency by using the admob account online or you can also set the refresh time in seconds using the API :
AdView.loadAd(new AdRequest());
Even though a call to the API will ask admob server to fetch a new ad, but that doesn't guarantee that a new ad will be fetched. Moreover, 1 second seems to be too short a interval to be refreshing your ads. If I was a user of your app, I would rather un-install it. :) But yes, that's my personal take on it..
I think too that the 1 sec, is very-very short time, for ad change, generate more data for the user (what csan be very annoying), but you know. :) You can set it on the admob's page, when you logged in. Choose your application, then Manage Settings. Here app settings. But it only allow at least 12 seconds, what confirms my thinking. And I think if you use what Anand said, you even won't got ads in every sec.
Hope it helps.
declare adView in activity as data member , then create Timer Task as bellow in your constructor of the activity
adView = (AdView) findViewById(R.id.adView);
TimerTask tt = new TimerTask() {
#Override
public void run() {
MainActivity.this.runOnUiThread(new Runnable() {
public void run() {
adView.loadAd(new AdRequest());
}
});
}
};
Timer t = new Timer();
t.scheduleAtFixedRate(tt, 0, 1000 * 60);

Categories

Resources