Can you show both banner ads and interstitial ads? - android

Can you show both banner ads and interstitial ads on the same activity? Is it against AdMob policy?
For example, when you open the app, interstitial ad shows up, and when you close it, banner ad shows up, or when banner ad is already showed you display interstitial ad.

Yes, you can.
Have a look at the documentation for more info
https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals
Also you might find using an "AdListener" very useful for your purposes!
adView.setAdListener(new AdListener() {
#Override
public void onAdClosed() {
//Called when the user is about to return to the application after
super.onAdClosed();
}
#Override
public void onAdFailedToLoad(int errorCode) {
//Called when an ad request failed
super.onAdFailedToLoad(errorCode);
}
#Override
public void onAdLeftApplication() {
//Called when an ad leaves the application (e.g., to go to the browser)
super.onAdLeftApplication();
}
#Override
public void onAdOpened() {
//Called when an ad is received
super.onAdOpened();
}
#Override
public void onAdLoaded() {
//Called when an ad opens an overlay that covers the screen
super.onAdLoaded();
}
});
You can fill each method with your own code :)

Ofcourse you can show both the banner ad and interstitial ad in you application. Here you go.
MainActivity.java add below lines of code in onCreate metho

Related

Ad not loaded after request

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.

Admob Banner Ads are not appearing after publishing my application

I published my Application few days ago in Play Store, everything works perfectly, the Ads (Banner & Interstitial) were appearing as expected. But today, i discovered that the Interstitial Ads are appearing but not Banner ads. This is my first application and I don't know what may be the problem.
Sometimes ads are not shown due to lack of ads in google's ad inventory. You can check ad request response code to be sure.
mAdView.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
}
#Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
Log.d("ADMOB_ERROR_CODE", "admob error code: " + errorCode);
}
#Override
public void onAdOpened() {
// Code to be executed when an ad opens an overlay that
// covers the screen.
}
#Override
public void onAdLeftApplication() {
// Code to be executed when the user has left the app.
}
#Override
public void onAdClosed() {
// Code to be executed when when the user is about to return
// to the app after tapping on an ad.
}
});
Further Reading: https://developers.google.com/admob/android/banner

Ads not displaying using real ad unit id instead of test ad unit id

In my application, I have integrated ads from AdMob. When I use my test unit ID, ca-
app-pub-3940256099942544/1033173712, it shows test ads successfully. However, when I use my production ad unit ID, it shows nothing.
In logcat, I see ads loading error code 0. Why are my ads failing to load?
This is the code I am using:
MobileAds.initialize(activity, main_interstial_addunit_id);
final InterstitialAd interstitialAd = new InterstitialAd(activity);
interstitialAd.setAdUnitId(main_interstial_addunit_id);
AdRequest adRequest = new AdRequest.Builder().build();
interstitialAd.loadAd(adRequest);
interstitialAd.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
if (interstitialAd.isLoaded()) {
interstitialAd.show();
}
}
#Override
public void onAdClosed() {
}
#Override
public void onAdFailedToLoad(int i) {
super.onAdFailedToLoad(i);
}
#Override
public void onAdLeftApplication() {
super.onAdLeftApplication();
}
#Override
public void onAdOpened() {
super.onAdOpened();
}
});
return interstitialAd;
So, as you are getting error code 0 this means "failed to load ads"
From this conversation,
It could be that you have only recently created a new Ad Unit ID and requesting for live ads. It could take a few hours for ads to start getting served if that is that case. If you are receiving test ads then your implementation is fine. Just wait a few hours and see if you are able to receive live ads then. If not, can send us your Ad Unit ID for us to look into.
So, after some times you will be automatically get ads.
Important: Ad type of your ad unit id needs to be same of ad type where you set that id

Admob native ads is not showing even if onAdLoaded is firing

I have integrated Admob native ads. I have used same adUnitId in multiple screen to load native ads. In most of the screen my code is working fine but in some screen onAdLoaded overridden method is calling but ads is not displaying.
I am using below code to native ads.
nativeExpressAdView.setAdListener(new AdListener() {
#Override
public void onAdFailedToLoad(int i) {
super.onAdFailedToLoad(i);
nativeExpressAdView.setVisibility(View.GONE);
}
#Override
public void onAdLeftApplication() {
super.onAdLeftApplication();
nativeExpressAdView.setVisibility(View.GONE);
}
#Override
public void onAdLoaded() {
super.onAdLoaded();
nativeExpressAdView.setVisibility(View.VISIBLE);
}
nativeExpressAdView.loadAd(new AdRequest.Builder().build());
nativeExpressAdView.setVisibility(View.VISIBLE);
View of Nativeexpressview
<com.google.android.gms.ads.NativeExpressAdView
android:id="#+id/nativeExpressAdView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:adSize="300x250"
android:layout_marginTop="#dimen/card_margin"
app:adUnitId="#string/ad_unit_id"/>
onAdLoaded() method is firing but ads is not loading. Can any one pls help me to identify the issue.
After you show an add always bring the banner to front
nativeExpressAdView.bringToFront()
I do that in onresume as well.

Admob android cannot change from banner INVISIBLE to VISIBLE

How do you people use admob banner? Can you please take a look at my code and show what is wrong with it. I have a game that has a Pause screen and it has much room to place a banner.
However when I load it, banner takes too long to show up in slow connection. So i made to load it up but keep it INVISIBLE, then make it visible when I need it. But it's not work. The banner won't visible! Please give me any advice...
Here is the code:
//Admob request Banner
bannerAdmob = new AdView(this);
bannerAdmob.setAdSize(AdSize.WIDE_SKYSCRAPER);
bannerAdmob.setAdUnitId(Setting.admobBannerId);
requestAdmobBanner();
I use handler to choose adunit. Interstitial is work nice, but neither banner.
protected Handler handlerAdmob = new Handler() {
#Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 1: //If is interstitial
if (interstitialAdmob.isLoaded()) {
interstitialAdmob.show();
} else {
requestAdmobInterstitial();
}
break;
case 2: //If is banner
bannerAdmob.setVisibility(View.VISIBLE);
break;
case 6: //Hide banner
bannerAdmob.destroy();
requestAdmobBanner(); //Request new banner
}
}
};
Then the method to load banner
private void requestAdmobBanner() {
AdRequest bannerRequest = new AdRequest.Builder()
// Add a test device to show Test Ads
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice(Setting.Device_ID)
.build();
// Load the banner ad.
bannerAdmob.loadAd(bannerRequest);
// Now we add ads listener for Admob banner so we can SHOW and HIDE it
bannerAdmob.setAdListener(new AdListener() {
#Override
public void onAdFailedToLoad(int errorCode) { // On admob interstitial failed to load, request new ad
bannerAdmob.setVisibility(View.GONE);
}
#Override
public void onAdLoaded() {
bannerAdmob.setVisibility(View.INVISIBLE);
System.out.println("Banner Admob is load, but still INVISIBLE");
}
});
}
You are setting the AdView to be INVISIBLE, when you should be setting it to VISIBLE. See code below:
// Now we add ads listener for Admob banner so we can SHOW and HIDE it
bannerAdmob.setAdListener(new AdListener() {
#Override
public void onAdFailedToLoad(int errorCode) { // On admob interstitial failed to load, request new ad
bannerAdmob.setVisibility(View.GONE);
}
#Override
public void onAdLoaded() {
bannerAdmob.setVisibility(View.VISIBLE);
System.out.println("#onAdLoaded - making AdView visible");
}
});

Categories

Resources