AdMob ads not showing in android layout

不问归期 提交于 2020-05-28 06:29:45

问题


I have an android app and I want add adMob ads. I have below codes, when I listen adView with onReceiveAd() the ads comes but not shows in layout Any idea?

adsLayout = (LinearLayout) findViewById(R.id.ads);
adView = new AdView(this, AdSize.SMART_BANNER, Constants.adMobId);
adsLayout.addView(adView);
adView.loadAd(new AdRequest().setTesting(true));

I have also internet permission and admob configchanges in manifest

adsLayout is

<LinearLayout
    android:id="@+id/adsLayout"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:layout_gravity="bottom"
    android:background="@android:color/white" >
</LinearLayout>

I pass publisherId with below code

adView = new AdView(this, AdSize.SMART_BANNER, Constants.adMobKey);

回答1:


Try this step:

Set Permission to manifest file:

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

Put this code into onCreate Method:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Ad Code
    AdView adView = (AdView)this.findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest();
    adRequest.setTesting(true);
    adView.loadAd(adRequest);
    adView.loadAd(new AdRequest());
    // End Ad Code
}

Before Publishing setTestDevice to test

    AdManager.setTestDevices( new String[] {AdManager.TEST_EMULATOR});
    AdView adView = (AdView)findViewById(R.id.adView);
    adView.requestFreshAd();

Hope to help this



来源:https://stackoverflow.com/questions/17382419/admob-ads-not-showing-in-android-layout

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