我是 AdMob 的新手,我在 admob 帐户中添加了应用名称和平台。在这个应用中,我添加了插页式广告的单元广告。并创建了它的广告单元 ID。
现在在 android studio 中,我按照 AdMob 的说明编写了简单的代码。因此,当单击按钮时,它会在我使用测试广告单元 ID时完美显示广告,但是当我使用自己创建的 ID 时,它不会加载,并且 logcat 显示如下:
07-04 23:47:25.165 17901-17914/h.safmical.kk W/Ads: There was a problem getting an ad response. ErrorCode: 0
07-04 23:47:25.169 17901-17901/h.safmical.kk W/Ads: Failed to load ad: 0
07-04 23:47:25.169 17901-17901/h.safmical.kk I/Ads: onAdFailedToLoad
07-04 23:47:33.028 17901-17901/h.safmical.kk D/TAG: The interstitial wasn't loaded yet.
07-04 23:50:57.947 17901-18143/h.safmical.kk E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb9aabcf0
我的主要活动:
MainActivity.java:
package h.safmical.kk;
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
public class MainActivity extends Activity {
private InterstitialAd mInterstitialAd;
Button click;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("*************************");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
click = (Button) findViewById(R.id.click);
click.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
Log.d("TAG", "The interstitial wasn't loaded yet.");
}
}
});
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
Log.i("Ads", "onAdLoaded");
}
@Override
public void onAdFailedToLoad(int errorCode) {
Log.i("Ads", "onAdFailedToLoad");
}
@Override
public void onAdOpened() {
Log.i("Ads", "onAdOpened");
}
@Override
public void onAdLeftApplication() {
Log.i("Ads", "onAdLeftApplication");
}
@Override
public void onAdClosed() {
mInterstitialAd.loadAd(new AdRequest.Builder().build());
}
});
}
}
我的 Gradle 文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "h.safmical.kk"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.android.gms:play-services-ads:10.2.4'
testCompile 'junit:junit:4.12'
}
请帮我解决这个问题。