Admob Banner Ads are not appearing after publishing my application - android

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

Related

Admob Ads not showing in android application

I created an account at Admob since a month, and i added payment method since 2 days ago.
a test device showing ads successfully. but other devices don't show any thing with error code:3
Ads: Ad failed to load : 3
public class MainActivity extends AppCompatActivity implements RewardedVideoAdListener {
private AdView adView;
private Button onePlayer, twoPlayer, exit;
private InterstitialAd mInterstitialAd;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(this, getString(R.string.app_id));
MobileAds.initialize(this, initializationStatus -> {
});
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(getString(R.string.instruction));
mInterstitialAd.loadAd(new AdRequest.Builder().addTestDevice("my-device-id").build());
mInterstitialAd.setAdListener(InterstitialListener);
adView = findViewById(R.id.adView);
adView.loadAd(new AdRequest.Builder().addTestDevice("my-device-id").build());
adView.setAdListener(adListener);
}
}
and i created a listener for InterstitialAd
private AdListener InterstitialListener = new AdListener() {
#Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
mInterstitialAd.show();
}
#Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
Toast.makeText(getApplicationContext(), "errorCode " + errorCode + "", Toast.LENGTH_LONG).show();
}
#Override
public void onAdOpened() {
// Code to be executed when the ad is displayed.
}
#Override
public void onAdClicked() {
// Code to be executed when the user clicks on an ad.
}
#Override
public void onAdLeftApplication() {
// Code to be executed when the user has left the app.
}
#Override
public void onAdClosed() {
// Code to be executed when the interstitial ad is closed.
}
};
and this is banner xml:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="#string/banner">
</com.google.android.gms.ads.AdView>
Note: the app doesn't uploaded to store yet!
how can i fix this problem?
This answer might help someone in future. I had the same problem. Ads were working fine in test devices. But in real device it did not display any ad.
I published my app to google play and downloaded it. In the app downloaded from google play, Ads are showing fine. I did not make any changes to the code
I am not sure why this happens, it's kind of black box.
Some answers in stack overflow says no need to publish app for showing ads. But it was not true in my case.
Your code seems fine.
Are you using this test unit ID for your banner?
ca-app-pub-3940256099942544/6300978111
Or are you using the one from your AdMob account?

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.

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.

Can you show both banner ads and interstitial ads?

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

Categories

Resources