【发布时间】:2018-10-14 11:02:41
【问题描述】:
所以我想在我的应用中实现一个插页式广告。我开始使用测试广告进行测试,但它们不起作用。我从 onAdFailedToLoad() 方法中得到错误代码 3。此外,我尝试显示此示例中的插页式广告,但它也无法正常工作 https://github.com/googleads/googleads-mobile-android-examples。我试图从牛轧糖操作系统 btw 运行它
这是我的代码:
在onCreate()中调用setupAds()方法
private void setupAds() {
//MobileAds.initialize(this, "AD_ID");
MobileAds.initialize(this,
"AD_ID");
mInterstitial=new InterstitialAd(this);
mInterstitial.setAdUnitId("AD_ID");
mInterstitial.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
Toast.makeText(PopupActivity.this, "onAdlOOADED", Toast.LENGTH_SHORT).show();
}
@Override
public void onAdFailedToLoad(int errorCode) {
Toast.makeText(PopupActivity.this, "onAdfailedtoload" + errorCode, Toast.LENGTH_SHORT).show();
}
@Override
public void onAdOpened() {
Toast.makeText(PopupActivity.this, "onAdOpened", Toast.LENGTH_SHORT).show();
}
@Override
public void onAdLeftApplication() {
Toast.makeText(PopupActivity.this, "onAdleftaplication", Toast.LENGTH_SHORT).show();
}
@Override
public void onAdClosed() {
Toast.makeText(PopupActivity.this, "onAdcLOASED", Toast.LENGTH_SHORT).show();
}
});
AdRequest request = new AdRequest.Builder().
addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
mInterstitial.loadAd(request);
((Button) mView.findViewById(R.id.test_ad_button)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mInterstitial.isLoaded()){
mInterstitial.show();
}
}
});
}
我在这里展示广告:
if (!isFirstStarted()){
if (mInterstitial.isLoaded()){
mInterstitial.show();
}
}
这是清单的 sn-p:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher_round"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ID"/>
【问题讨论】:
-
你确定你的 App ID 在
AndroidManifest和 MobileAdSDK 初始化时是一样的
标签: java android admob interstitial