1

I want to display ads on my activity. For this I added next lines on manifest:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<activity
        android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        android:theme="@android:style/Theme.Translucent" />

on activity xml have:

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    ads:adSize="BANNER"
    ads:adUnitId="@string/banner_ad">
</com.google.android.gms.ads.AdView>

and on activity:

private AdView mAdView;
....
 mAdView = (AdView) findViewById(R.id.adView);
 if (Utils.IS_ADMOB_IN_DEBUG) {
        adRequest = new AdRequest.Builder().
                addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                .addTestDevice("00000F800094960000B45A000000D22")
                .build();
    } else {
        adRequest = new AdRequest.Builder().build();
    }
mAdView.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
        }

        @Override
        public void onAdClosed() {
        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
        }

        @Override
        public void onAdLeftApplication() {
        }

        @Override
        public void onAdOpened() {
            super.onAdOpened();
        }
    });

    mAdView.loadAd(adRequest);

I have added unit Ad ID on string banner_ad.

Despite my efforts, I can not show anything on adView. All work perfect for debug mode. Just on debug mode.

Any suggestion please?

gogoloi
  • 627
  • 3
  • 8
  • 19
  • When you say it works in debug mode, do you mean you are seeing the test ad, but you are not seeing a proper ad when you are not on your test device. Have you looked in the logcat, sometimes if an ad request fails it will tell you – Boardy Jul 12 '17 at 15:15
  • All looking ok on debug mode. I/Ads: Ad finished loading. Else I get W/Ads: Failed to load ad: 0 – gogoloi Jul 12 '17 at 15:23
  • Is it a new Admob account you're using. Google'ing the error brought up this SO post (https://stackoverflow.com/questions/38378002/admob-ads-not-loading-failed-to-load-ad-0). It looks like it takes a little time before your account will start working and serving adds, one of the comments suggested it was about an hour, although I guess it could take anything up to 24 hours potentially – Boardy Jul 12 '17 at 15:46
  • I see now this error. Don't know what mean: 07-12 18:49:01.613 13273-13273/ro.cc.cc E/ViewRootImpl: sendUserActionEvent() mView == null 07-12 18:49:01.922 13273-13273/ro.cc.cc D/ghiduldrumetului.ro:ActivityHome: onStop – gogoloi Jul 12 '17 at 15:50
  • sendUserActionEvent() mView == null is write with red on logcat – gogoloi Jul 12 '17 at 15:51
  • 1
    Your getting an error `Failed to load ad: 0`. If you have just signed up to AdMob, it will take time before Google servers can send you a proper ad when not in debug mode. Wait for a couple of hours, maybe even a day and try again and you should start seeing ads when not in debug mode – Boardy Jul 12 '17 at 15:51

2 Answers2

1

When create an adMob account MUST add payment information too.

gogoloi
  • 627
  • 3
  • 8
  • 19
0

Your account may be not approved. You can know error using:

@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
super.onAdFailedToLoad(loadAdError);
Log.d("ERROR",loadAdError.toString());}

After you know your error you can fix it here: https://support.google.com/admob/answer/9905175