My application opens a Publisher InterstitialAd whenever you start but when a user closes it reopens. This process happens constantly and then you can't use application, can anyone help me?
public void getIntertitalAds(boolean isPortraitMode)
{
interstitial = new PublisherInterstitialAd(context);
if(isPortraitMode)
interstitial.setAdUnitId(tags.getAdUnitInterstitial());
else
interstitial.setAdUnitId(tags.getAdUnitInterstitialTablet());
AdListener adListener = new AdListener() {
#Override
public void onAdLoaded() {
super.onAdLoaded();
if(interstitial!=null)
interstitial.show();
}
#Override
public void onAdClosed() {
super.onAdClosed();
interstitial = null;
}
};
// Create ad request.
PublisherAdRequest adRequest = new PublisherAdRequest.Builder()
.build();
// Begin loading your interstitial.
interstitial.setAdListener(adListener);
interstitial.loadAd(adRequest);
}
NEVER call interstitial.show() from AdListener#onAdLoaded(). You have no control over when it will be called and it presents a really poor user experience. Instead call interstitial.show() at a natural break point in your app.
There is no need to have separate AdUnitIds for portrait and landscape. Interstitials are the same regardless.
All the code in your getIntertitalAds() (sic) method should be Activity#onCreate
I strongly suspect your problems stem from a combination of 1 and 3.
Related
I want integrated AdMob into my app. but here is an issue we manually need to reload Ad for showing. I want to try when some close/Dismiss the Ad automatically load again that I called it again onAdDissmissed method. Is this a policy violation? or Is a good programming practice or not?
Here my code oncreate method
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
loadMethodAdMob();
}
load Method
public void loadMethodAdMob() {
AdRequest adRequest = new AdRequest.Builder().build();
InterstitialAd.load(this, AD_UNIT_ID, adRequest, new InterstitialAdLoadCallback() {
#Override
public void onAdLoaded(#NonNull InterstitialAd interstitialAd) {
// will be null until an ad is loaded.
MyActivity.this.interstitialAd = interstitialAd;
mToast("Ad Loaded");
interstitialAd.setFullScreenContentCallback(new FullScreenContentCallback() {
#Override
public void onAdDismissedFullScreenContent() {
MyActivity.this.interstitialAd = null;
mToast("The ad was dismissed.");
InterstitialAdMob(); // i called it here is this ok
}
#Override
public void onAdShowedFullScreenContent() {
mToast("The ad was shown.");
}
});
}
});
}
button click
public void buttonClickShowAd(){
if (interstitialAd != null) {
interstitialAd.show(this);
} else {
mToast("Ad did not load");
requestForReload();
}
}
You can load n-number of interstitial ads in advance so that it will be available when show method is called. Above code is perfectly fine.
Reference - https://developers.google.com/admob/android/interstitial#some_best_practices
Allow for adequate loading time.
Just as it's important to make sure you display interstitial ads at an appropriate time, it's also important to make sure the user doesn't have to wait for them to load. Loading the ad in advance by calling load() before you intend to call show() can ensure that your app has a fully loaded interstitial ad at the ready when the time comes to display one.
Don't flood the user with ads.
While increasing the frequency of interstitial ads in your app might seem like a great way to increase revenue, it can also degrade the user experience and lower clickthrough rates. Make sure that users aren't so frequently interrupted that they're no longer able to enjoy the use of your app.
However you might also want to check Disallowed interstitial implementation policy when you load multiple objects in advance.
https://support.google.com/admob/answer/6201362?hl=en
I am testing Ads in an Android app.
I want a button to be shown when the ad is loaded, and then click on the button to show the ad.
My issue is that the ad is never loaded.
This is my code so far:
MobileAds.initialize(getActivity(), "ca-app-pub-***");
mInterstitialAd = new InterstitialAd(getActivity());
mInterstitialAd.setAdUnitId("ca-app-pub-ca-app-pub-***");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
btnOfertar.setVisibility(View.GONE);
mInterstitialAd.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
Log.i("Ads", "onAdLoaded");
btnOfertar.setVisibility(View.VISIBLE);
}
});
You should try the following:
mInterstitialAd.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
// Add this
mInterstitialAd.show()
Log.i("Ads", "onAdLoaded");
btnOfertar.setVisibility(View.VISIBLE);
}
});
Also, try using the dedicated test ad id that Google provides in the documentation: ca-app-pub-3940256099942544/1033173712. If this loads properly your code should be okay.
Your actual ad might take a while to show up depending on how many requests you're getting to show the ad. Also make sure that your AdMob's payment is set up correctly.
Is it possible to load ads of Ad mob in starting of app and then use it in any button of whole project?
After click of any button it open quickly on every type of internet mainly on 2g
without taking time to load
it not a recommended way to show ads at start of the application as it result in poor user experience, like user might be interacting with your app and suddenly Ad pops up.
well if you still want to you can display it by overriding onAdLoad listener in your Activity's onCreate
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(getString(R.string.interstitialAd_id));
AdRequest adRequest = new AdRequest.Builder().build();
mInterstitialAd.loadAd(adRequest);
mInterstitialAd.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}
});
UPDATE:
With this method it will only display it if its loaded
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
Iam trying to display ad using Admob,but Iam not getting any call at onAdloaded.Can someone help...
Iam displaying an inerstitial ad.Iam setting and then Iam trying to load it...
#Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
CalligraphyConfig.initDefault(getString(R.string.font_alegreya_sans_regular));
setInterstitialAd();
setContentView(R.layout.splashscreen_activity);
}
private void setInterstitialAd() {
mInterstitial = new InterstitialAd(this);
mInterstitial.setAdUnitId(INTERSTITIAL_AD_ID);
// Create ad request.
AdRequest adRequest = new AdRequest.Builder().build();
// Begin loading your interstitial.
mInterstitial.loadAd(adRequest);
mInterstitial.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
displayInterstitial();
}
#Override
public void onAdFailedToLoad(int errorCode) {
}
});
}
private void initAdView() {
AdView mAdView = (AdView) findViewById(R.id.ad_container_layout);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}
You should'nt have displayInterstitial() inside onAdLoaded(). This is causing the outcome of Ad not being shown. Either show an Ad after some level or user made action like after five level, one is displaying an interstitial, it comes in the pause menu. you keep it loaded from before and display it on the fifth level. or you can have it in that pause menu after some amount of time using a timer ( in which displayInterstitial() ) is included.
Suraj, add some log into both callback methods. One of them will be called.
I suspect the ad request is failing for reason, so onFailedToLoad() will be getting called instead.
Also DON'T call displayInterstitial() from onAdLoaded(). This causes really poor user experience and is likely to get your Admob account banned.
i want to have an admob interstitial ad show up when the user first opens the app or when the user navigates to another app (like browser) and then returns to my app. This is my current code for interstital ad, this code is entirely contained inside the OnCreate method.
// Create the interstitial.
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("ca-app-pub-XXXXXXXXXXXXXXXX");
// Create ad request.
AdRequest adRequest2 = new AdRequest.Builder().build();
// Begin loading your interstitial.
interstitial.loadAd(adRequest2);
interstitial.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
});
This seems to work for most situations, but on certain devices this will create a loop of interstitial showing 2-3 sec after they are dismissed by the user. one of those device that has the loop is a Galaxy Tab3 . i cant seem to figure out a proper way to setup my code so that this behavior does not happen on any device.
Use the following code to display the interstitial ad when appstarts.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("***********");
AdRequest adRequest = new AdRequest.Builder().build();
interstitial.loadAd(adRequest);
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
displayInterstitial();
}
});
}
public void displayInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
Create a boolean var to assist with it..
boolean ad_shown = false;
When you do .show() turn the variable to true.
Don't forget to put a guard on the if
if (interstitial.isLoaded() && !ad_shown) {