我是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'
}
请帮我解决这个问题。