0

I'm trying to display AdMob NativeExpressAds in my Android application.

Sample ads show up in the emulator and I thought everything seems fine.

However, on actual testing on real Android devices, ads refuse to show up - whether or not I set addTestDevice("...").

My code is:

public NativeExpressAdView getNativeExpressAdView(Activity activity) {
    NativeExpressAdView adView = new NativeExpressAdView(activity);
    adView.setAdListener(new TestAdListener(adView));
    adView.setAdSize(new AdSize(adWidth, adHeight));
    adView.setAdUnitId(adUnitID);
    AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
    //adRequestBuilder.addTestDevice("187AE74C3A6B5BA1B5E94A46EC9FD3F6");
    adView.loadAd(adRequestBuilder.build());
    return adView;
}

Note: the adWidth and adHeight is exactly the same as what is set in the AdMob AdUnit.

and:

...

    @Override
    public void onAdLoaded() {
        super.onAdLoaded();
        Log.i("I/Ads", "onAdLoaded");
    }

Yes, onAdLoaded is indeed called.

I also tried this, but it didn't work. I also research many other materials, but none worked.

EDIT: I debugged further and found this error: 09-04 13:53:46.204 2502-2502/com.swars.android W/Ads: Not enough space to show ad. Needs 360x100 dp, but only has 320x0 dp.

The size is the same size as set in AdMob AdUnit. So, it seems that I should make is smaller. However, there is a mystery about the error because it says the height is 0 (320x0 dp). Can anyone help to shed some lights on this?

Krupa Kakkad
  • 857
  • 1
  • 13
  • 28
ikevin8me
  • 4,253
  • 5
  • 44
  • 84

1 Answers1

1

Config your RelativeLayer, so :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 ...
 android:paddingLeft="0dp"
 android:paddingRight="0dp"
 ...
>

AdView config to:

<com.google.ads.AdView
android:id="@+id/adMobadView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
...
/>

Source