繁体   English   中英

AdMob广告未在模拟器中显示-Android应用

[英]AdMob adverts not showing in Emulator - Android App

我一直在尝试让AdMob广告显示在Android应用模拟器中。 我使用的是Eclipse,当我单击“图形设计”时,它显示一个白色矩形(广告将在此处显示)并显示“ Google提供的广告”。

但是,当我在模拟器上运行广告时,没有广告出现。

我逐字逐字地遵循了Google开发页面上的指南,并认为它可以正常工作。

有任何想法吗?

提前致谢!

编辑:这是我的代码:

在XML中:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/beach"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="16dp"
    ads:adSize="BANNER"
    ads:adUnitId="MY ADD ID (it's filled in in my code)" >
</com.google.android.gms.ads.AdView>

在活动中:

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

public class MainActivity extends Activity {

private static final String TEST_DEVICE_ID = "INSERT_YOUR_TEST_DEVICE_ID_HERE";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // The "loadAdOnCreate" and "testDevices" XML attributes no longer available.
    AdView adView = (AdView) this.findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder()
    .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
    .addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")

        .build();
    adView.loadAd(adRequest);

}

尝试通过将以下代码行放入您的代码中:

AdRequest adRequest = new AdRequest.Builder()
        .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)    // remove if in real time use
        .addTestDevice(getDeviceId())       // remove if in real time use
        .build();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM