Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know if AdMob ad has been loaded

Tags:

My Andorid app works offline and online. It displays ads when it is in online mode. In a scenario where it is working in offline mode and user switches the internet connectivity on, I want to know if the ad is already loaded. If not, then I would load a new ad. I looked at AdMob API (AdView class) but could not find something that does this.

Here is the implementation of my AdListener according to the answer from @Hounshell. But none of the methods implemented here are getting executed.

        adView.setAdListener(new AdListener() {          @Override         public void onReceiveAd(Ad arg0) {             Toast.makeText(act, "Ad received",Toast.LENGTH_LONG).show();         }          @Override         public void onPresentScreen(Ad arg0) {         }          @Override         public void onLeaveApplication(Ad arg0) {             // TODO Auto-generated method stub          }          @Override         public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {             Toast.makeText(act, "Failed to receive Ad",Toast.LENGTH_LONG).show();         }          @Override         public void onDismissScreen(Ad arg0) {             // TODO Auto-generated method stub          }     }); 

And part of main.xml that covers the AdView

<FrameLayout                      android:layout_width="fill_parent"                     android:layout_height="50dp"                     >                 <com.google.ads.AdView                     xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"                     android:id="@+id/adView"                     android:layout_width="fill_parent"                     android:layout_height="fill_parent"                     ads:adSize="BANNER"                     ads:adUnitId="xxxxxxxxxxxxxxxx"                     ads:loadAdOnCreate="true" />                 </FrameLayout> 
like image 436
Balkrishna Rawool Avatar asked Mar 21 '12 00:03

Balkrishna Rawool


People also ask

How do I know if AdMob ad is working?

The quickest way to enable testing is to use Google-provided test ad units. These ad units are not associated with your AdMob account, so there's no risk of your account generating invalid traffic when using these ad units. So, if you use the provided test admob id, you should be loading test ads.

How check ad is loaded or not in Android?

You can use the getResponseInfo() method to retrieving information about the loaded ad. Show activity on this post. you can use isLoaded() method. I am using it on a same context as you and inside a timer to wait until ad is loaded.

How long does it take for AdMob to show ads?

When apps are newly registered with AdMob, it typically takes up to an hour and a few ad requests to allow inventory to build. Because of this, you may not see live impressions immediately. Note: In some cases, it may take longer than an hour. Please wait 24 hours before seeking additional help.

Why is my AdMob ads not showing?

Make sure you have updated AdMob with your payment details. Make sure that the ads you created in AdMob are banner ads. Check your AdMob dashboard to see the status of your ads, are they active? Verify you used the correct Ad Unit Id.


2 Answers

From https://developers.google.com/mobile-ads-sdk/docs/android/intermediate#adlistener

AdView.setAdListener(new AdListener() {       // Implement AdListener     }); 

Your AdListener's onReceiveAd() will be called when an ad is available, onFailedToReceiveAd() will be called whan an ad isn't available with a code explaining why (including network not available and no fill)

Update:

Same basic answer, new URL: https://developers.google.com/admob/android/banner?hl=en

like image 86
Hounshell Avatar answered Sep 21 '22 11:09

Hounshell


Simply...!!!

final AdView mAdView = (AdView) findViewById(R.id.adView);         mAdView.setVisibility(View.GONE);     mAdView.setAdListener(new AdListener() {         private void showToast(String message) {             Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();         }          @Override         public void onAdLoaded() {             showToast("Ad loaded.");             if (mAdView.getVisibility() == View.GONE) {                 mAdView.setVisibility(View.VISIBLE);             }         }          @Override         public void onAdFailedToLoad(int errorCode) {             showToast(String.format("Ad failed to load with error code %d.", errorCode));         }          @Override         public void onAdOpened() {             showToast("Ad opened.");         }          @Override         public void onAdClosed() {             showToast("Ad closed.");         }          @Override         public void onAdLeftApplication() {             showToast("Ad left application.");         }     });       AdRequest adRequest = new AdRequest.Builder().build();     mAdView.loadAd(adRequest); 
like image 35
Waqar Vicky Avatar answered Sep 23 '22 11:09

Waqar Vicky