AdMob广告未在Android版式中展示 [英] AdMob ads not showing in android layout

查看:193
本文介绍了AdMob广告未在Android版式中展示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用,我想添加adMob广告.我有以下代码,当我使用onReceiveAd()收听adView时,广告出现了,但没有在布局中显示.有什么想法吗?

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));

我还有清单中的互联网许可和admob configchanges

I have also internet permission and admob configchanges in manifest

adsLayout是

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>

我通过以下代码传递PublisherId

I pass publisherId with below code

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

推荐答案

尝试此步骤:

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

将此代码放入onCreate方法:

@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
}

在发布setTestDevice进行测试之前

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

希望可以帮助您

这篇关于AdMob广告未在Android版式中展示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆