Can't add ads to my app.

前端 未结 5 565
渐次进展
渐次进展 2021-01-18 07:57

So I followed this guide from admob with Google Play Services, https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals#play And I have encountered a problem. Th

相关标签:
5条回答
  • 2021-01-18 08:25

    Use

    AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
    adView.loadAd(adRequestBuilder.build());
    

    EDIT:

    Remove

    setContentView(R.layout.menu);
    

    add behind loadAd()

    setContentView(layout);
    
    0 讨论(0)
  • 2021-01-18 08:43

    You can use layout to show your add. Just put below code in your layout where ever you want into the screen.

         <com.google.ads.AdView
                android:id="@+id/ad"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                ads:adSize="SMART_BANNER"
                ads:adUnitId="Your AddMob ID"
                ads:loadAdOnCreate="true"
                ads:testDevices="TEST_EMULATOR,TEST_DEVICE_ID_GOES_HERE" />  
        </RelativeLayout>
    

    You should have the newest GoogleAdmobSdk.jar in you libs folder. This is working for me.

    0 讨论(0)
  • 2021-01-18 08:43

    Try to add directly at the import area the following lines

    import com.google.android.gms.ads.AdRequest;
    import com.google.android.gms.ads.AdSize;
    import com.google.android.gms.ads.AdView;
    

    If you are migrating to new way of use addMob don`t forget to remove the old library.

    0 讨论(0)
  • 2021-01-18 08:49
    import com.google.android.gms.ads.AdRequest;
    import com.google.android.gms.ads.AdSize;
    import com.google.android.gms.ads.AdView;
    

    AND adding following into layout:

    <com.google.ads.AdView
                android:id="@+id/ad"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                ads:adSize="SMART_BANNER"
                ads:adUnitId="Your AddMob ID"
                ads:loadAdOnCreate="true"
                ads:testDevices="TEST_EMULATOR,TEST_DEVICE_ID_GOES_HERE" /> 
    

    works

    0 讨论(0)
  • 2021-01-18 08:51

    Remove any other ad sdk(in my case it was adfonic) from your project as there is a conflict and try. Happy Coding :)

    0 讨论(0)
提交回复
热议问题