为什么我无法使用我的单元 ID 在我的应用程序上显示我的 AdMob 插页式广告?

Why Can't I Get My AdMob Interstitial Ads To Show On My App Using My Unit ID?

我正在创建一个将通过 Google AdMob 显示插页式广告的应用程序。我检查并仔细检查了我的代码,看看我是否错过了一步或有什么地方不对,根据这个 website,我可以说它是正确的。如果我使用他们提供给我们的测试 ID 进行测试,广告就会弹出。如果我用将近两周前创建的测试 ID 替换我的测试 ID,它不会弹出。我在 logcat...

中收到以下错误
E/GmsClient: unable to connect to service: com.google.android.gms.leibniz.events.service.START on com.google.android.gms

这是我的代码...

MainActivity.Java

下面的代码在onCreate上面。

private InterstitialAd mInterstitialAd;

以下代码在onCreate下

 MobileAds.initialize(view.getContext(), new OnInitializationCompleteListener() {
                @Override
                public void onInitializationComplete(InitializationStatus initializationStatus) {}
            });
            AdRequest adRequest = new AdRequest.Builder().build();

            InterstitialAd.load(view.getContext(), myAdUnitID, adRequest,
                    new InterstitialAdLoadCallback() {
                        @Override
                        public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
                            mInterstitialAd = interstitialAd;
                            Log.i(TAG, "onAdLoaded");
                            if (mInterstitialAd != null) {
                                mInterstitialAd.show(this);
                            } else {
                                Log.d("TAG", "The interstitial ad wasn't ready yet.");
                            }
                        }

                        @Override
                        public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
                            Log.i(TAG, loadAdError.getMessage());
                            mInterstitialAd = null;
                        }
                    });

Manifest.xml

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

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher_therm_icon"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_therm_icon_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.TempConverter">
        <activity android:name=".MainActivity"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".Help"
            android:theme="@style/Theme.TempConverter"
            android:parentActivityName=".MainActivity"
            android:label="Help"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.support.PARENT_ACTIVITY"/>
                <category android:name="com.mathiasapps.tempconverter.Help"/>
            </intent-filter>
        </activity>
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-6771696786744697~7616850816"/>
    </application>
</manifest>

Build.gradle(项目)

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.1.3"
        classpath 'com.google.gms:google-services:4.3.10'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://maven.google.com/"}
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Build.gradle(模块)

plugins {
    id 'com.android.application'
}

android {
    compileSdkVersion 31
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.mathiasapps.tempconverterfreeversion"
        minSdkVersion 23
        targetSdkVersion 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
    implementation 'androidx.recyclerview:recyclerview:1.2.1'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'com.google.firebase:firebase-messaging:22.0.0'
    implementation 'com.google.firebase:firebase-analytics:19.0.2'
    implementation 'com.google.android.gms:play-services-ads:20.4.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

谢谢!感谢您的帮助!

您的插页式广告实施没有问题,您无需执行任何其他操作即可加载真实广告。

测试广告正在展示而您的真实广告没有展示,这是因为 Admob 在您的应用获得一定流量之前不会开始展示广告。您不应尝试从您的设备加载真实广告。因为 Admob 会检测到它并会在您的帐户中放置有限的广告投放

来自 Admob 文档

When building and testing your apps, make sure you use test ads rather than live, production ads. Failure to do so can lead to suspension of your account.

切勿使用真实广告进行测试,如果测试广告运行良好,则真实广告也能正常运行。