AdMob Ads Not Showing

被刻印的时光 ゝ 提交于 2019-12-05 20:57:21

I think in addition to this block that you already have:

AdRequest adRequest = new AdRequest.Builder()
        .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
        .addTestDevice("Device_ID")
        .build();

...You are missing something like this:

    AdView adView = (AdView) this.findViewById(R.id.adView);
    adView.loadAd(adRequest);

Here is complete picture:

  1. what is in xml file:

    <com.google.android.gms.ads.AdView android:id="@+id/adView"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      ads:adUnitId="your ad unit id"
      ads:adSize="BANNER"/>
    
  2. what is in onCreate:

    AdRequest adRequest = new AdRequest.Builder()
            .build();
    
    AdView adView = (AdView) this.findViewById(R.id.adView);
    adView.loadAd(adRequest);
    

Please note the code above is for production. You must use test device id for testing in order to avoid AdMob penalties.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!