gpt4 book ai didi

android - 不会加载实时 Admob 广告

转载 作者:行者123 更新时间:2023-12-04 10:07:24 28 4
gpt4 key购买 nike

我在尝试显示来自 Admob 的实时广告时遇到问题。测试广告工作正常,但当我切换到实时广告时,我不断收到此错误

 Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: 
java.lang.IllegalStateException:
The Google Mobile Ads SDK was initialized incorrectly

我遵循了 Admob 提供的文档并检查了 APP_ID,但仍然不断收到此错误。我似乎无法弄清楚问题是什么。我已经在下面发布了我的代码,有什么建议吗?

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.whatsfor">

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

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-123123123123-43434323"/>
</activity>
</application>
</manifest>

主程序
public class MainActivity extends AppCompatActivity {
AdView bannerAdView;

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

MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
bannerAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
bannerAdView.loadAd(adRequest);
}}

Activity .xml
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
app:adSize="BANNER"
app:adUnitId="ca-app-pub-6969696969/123123123"
android:layout_width="320dp"
android:layout_height="53dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginStart="47dp"
android:layout_marginLeft="47dp"
android:layout_marginTop="69dp"
android:layout_marginEnd="37dp"
android:layout_marginRight="37dp"
android:layout_marginBottom="68dp" />

最佳答案

您必须放置 App ID <meta-data><application>不低于 <activity> .

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-123123123123-43434323"/>

<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

或者, the Official document提到:

Important: This step is required as of Google Mobile Ads SDK version 17.0.0. Failure to add this tag results in a crash with the message: The Google Mobile Ads SDK was initialized incorrectly.

关于android - 不会加载实时 Admob 广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61514202/

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