gpt4 book ai didi

android - AdMob 横幅广告请求失败,代码为 ERROR_CODE_INVALID_REQUEST 1

转载 作者:行者123 更新时间:2023-11-29 17:26:08 25 4
gpt4 key购买 nike

我在显示 AdMob 横幅时遇到了一些问题。我收到错误 1,这意味着 ERROR_CODE_INVALID_REQUEST。当我更改 setAdUnitId 并使用 UnitId 进行测试时,它起作用了。但是,当我使用 AdMob 提供的 UnitId 时,出现错误。

这是布局:

<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="#262626"
tools:context="com.elis91.elis.contatti.Contatti">

<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#1e88e6"
android:orientation="horizontal">

<TextView
android:id="@+id/textView5MSGnonLetti"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="You have 0 new messagges"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#cdfff9f9"
android:textSize="20dp"/>
</LinearLayout>

<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/linearLayout"
android:layout_above="@+id/relativeLayout3"/>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="52dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/relativeLayout3"
android:gravity="bottom">

<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@+id/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>

</RelativeLayout>

这是安卓:

    private void setupGoogleAds(){
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
//.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();

mAdView.loadAd(adRequest);
mAdView.setAdListener(new AdListener() {
@Override
public void onAdOpened() {
Log.d("esx", "onAdOpened");
// Save app state before going to the ad overlay.
}

@Override
public void onAdLoaded() {
Log.d("esx", "onAdLoaded");
// Save app state before going to the ad overlay.
}

@Override
public void onAdFailedToLoad(int errorCode) {

Log.d("esx", "onAdFailedToLoad: " + errorCode+"--"+AdRequest.ERROR_CODE_NO_FILL+"-"+AdRequest.ERROR_CODE_NETWORK_ERROR+"-"+AdRequest.ERROR_CODE_INVALID_REQUEST+"-"+AdRequest.ERROR_CODE_INTERNAL_ERROR+"-");
// Save app state before going to the ad overlay.
}

@Override
public void onAdClosed() {
Log.d("esx", "onAdClosed");
// Save app state before going to the ad overlay.
}

@Override
public void onAdLeftApplication() {
Log.d("esx", "onAdLeftApplication");
// Save app state before going to the ad overlay.
}
});
}

最佳答案

ERROR_CODE_INVALID_REQUEST 表示:

The ad request was invalid; for instance, the ad unit ID was incorrect.

Source

检查您传递的广告单元 ID 是否正确。

我检查了您的代码,认为问题出在此处。

你写了

ads:adUnitId="@+id/banner_ad_unit_id"

你一定是想写

ads:adUnitId="@string/banner_ad_unit_id"

假设您已将广告单元 ID 存储在字符串资源中。如果它不在您的字符串资源中,则直接如下所示:

ads:adUnitId="XXXXXXXXXXXXXXXX" // Replace XXXXXXXXXXXXXXXX with your ad unit id.

关于android - AdMob 横幅广告请求失败,代码为 ERROR_CODE_INVALID_REQUEST 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34569771/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com