我正在创建一个应用程序,它将通过Google AdMob显示间隙广告。我已经检查和双重检查了我的代码,看看我是否错过了一步或什么东西不对,从我可以告诉它是正确的,根据这个网站。如果我使用测试id,他们提供给我们用于测试,广告将弹出。如果我用我两周前创建的测试id替换,它不会弹出。我在我的日志中得到了以下错误..。
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'
}谢谢!我很感激你的帮助!
发布于 2021-10-07 01:53:50
您的间隙广告实现是好的,你不需要做任何其他事情来加载真正的广告。
测试广告正在显示,而你的真实广告不显示,因为Ad暴民不会开始显示广告,直到你在你的应用上获得一定数量的流量。你不应该尝试从你的设备加载真正的广告。因为Admob会发现它,并将有限的广告服务在您的帐户上。
来自Admob文档
在构建和测试你的应用程序时,确保你使用测试广告而不是现场制作广告。不这样做可能会导致您的帐户暂停。
永远不要测试真实的广告,如果测试广告运行良好,那么真实的广告也会起作用。
https://stackoverflow.com/questions/69474152
复制相似问题