1

我有一个 android 应用程序,我想添加 adMob 广告。我有以下代码,当我使用 onReceiveAd() 收听 adView 时,广告会出现但不会在布局中显示任何想法?

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

adsLayout 是

<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

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

1 回答 1

1

试试这个步骤:

设置清单文件的权限:

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

希望对此有所帮助

于 2014-03-06T16:23:24.313 回答