0

我已经用 Android Studio 制作了我的应用程序,现在我有了一个完成的应用程序。我在我的应用程序中添加了一个 AdView,并使用了 TestAd-UnitId,我得到了测试广告。在我的模拟器和手机上。那行得通,我运行了测试广告。然后我创建了一个 AdMob 帐户,并在其中添加了我的应用程序,创建了一个 Bannner 广告,就像我在我的应用程序中一样,并使用了来自 AdMob 页面的 adUnitId。但是当我在手机上运行我的应用程序时,我根本没有收到任何广告。以防万一:该应用不在 Play 商店中。

我读到您必须等待几个小时才能获得实时广告,但我已经等待了超过 12 小时,我的手机上仍然没有收到任何广告。

如果你需要它,这是我的代码:

我的广告视图:

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toBottomOf="parent"
    ads:adSize="BANNER"
    ads:adUnitId="@string/banner_ad_unit_id"
    android:layout_marginBottom="16dp"
    android:layout_marginLeft="8dp"
    app:layout_constraintLeft_toLeftOf="parent"
    android:layout_marginRight="8dp"
    app:layout_constraintRight_toRightOf="parent" />

我的 onCreate 方法:

MobileAds.initialize(getApplicationContext(), "ca-app-pub-hiddenhiddenhide~hiddenhide");

AdView ad = (AdView) findViewById(R.id.adView);
AdRequest request = new AdRequest.Builder().build();
ad.loadAd(request);
4

1 回答 1

1

您需要将此行添加到构建器。

.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)

所以你需要有这样的东西:

AdRequest request = new AdRequest.Builder()
                        .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                        .build();

如果您想使用自己的手机。您可以在需要添加的 logcat 中查找 id,它看起来像这样:

AdRequest request = new AdRequest.Builder()
                    .addTestDevice("here goes your id of your phone")
                    .build();

您需要这样做的原因是因为在开发时您看不到添加,因为应用程序未放置在 playstore 中。只要他不在 Playstore 中,您就不会看到广告。您可以使用刚刚提供的代码创建测试广告

如果您进入生产环境,请尝试使用以下代码:(它将使用测试设备进行调试和开发,但在生产环境中也会为您的设备使用真正的添加)

    AdRequest adRequest = new AdRequest.Builder()
            .build();
    if (BuildConfig.DEBUG)
        adRequest = new AdRequest.Builder()
                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                .addTestDevice("your id goes here")
                .build();
于 2017-03-28T12:21:58.173 回答