我刚刚创建了一个新项目,我首先实现的是Interstitial ad,我将Admob像这样implementation 'com.google.android.gms:play-services-ads:17.1.3'
导入到依赖项中,然后在Android Manifest中添加了我的应用程序ID
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="My App Id"/>
现在我创建了非页内广告,我导入了我的添加单元,但它无法正常运行,它在左侧显示了这样的测试广告,如,当我构建apk并尝试将其安装在真正的设备根本不显示,所以这是我的插页式代码
private void launchInter() {
interstitialAd = new InterstitialAd(this);
interstitialAd.setAdUnitId("interstitialadunit");
//set the adListener
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
showAdInter();
}
@Override
public void onAdFailedToLoad(int errorCode) {
String message = String.format("onAdFailedToLoad (%s)", getErrorReason(errorCode));
}
@Override
public void onAdClosed() {
if (exitApp)
finish();
}
});
}
private void showAdInter() {
if (interstitialAd.isLoaded()) {
interstitialAd.show();
} else {
Log.d("", "Intersitial ad was not ready to be shown");
}
}
public void loadInterstitial() {
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("")
.build();
//Lad the interstitial aa
interstitialAd.loadAd(adRequest);
}
//Get string errror reason from ad error
private String getErrorReason(int errorCode) {
String errorReason = "";
switch (errorCode) {
case AdRequest.ERROR_CODE_INTERNAL_ERROR:
errorReason = "Internal Error";
break;
case AdRequest.ERROR_CODE_INVALID_REQUEST:
errorReason = "Invalid Request";
break;
case AdRequest.ERROR_CODE_NETWORK_ERROR:
errorReason = "Network Error";
break;
case AdRequest.ERROR_CODE_NO_FILL:
errorReason = "No fill";
break;
}
return errorReason;
}
和onCreate方法我这样称呼
launchInter();
loadInterstitial();
我在做错什么,请帮忙,如果您需要更多信息,请告诉我