我正在尝试升级到谷歌播放服务Admob版本,但我似乎无法找到正确的方式来显示间隙广告后,尝试了几天,横幅视图似乎显示正常,它只有插页式广告那是个问题。
这是我参考Google Play服务后的当前代码。
private InterstitialAd interstitial;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("TEST_DEVICE_ID")
.build();
adView.loadAd(adRequest);
// Create the interstitial.
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("XXXXXXXXXXXXXXXXXXX");
// Create ad request.
AdRequest adRequestIN = new AdRequest.Builder().build();
// Begin loading your interstitial.
interstitial.loadAd(adRequestIN);
}
// Invoke displayInterstitial() when you are ready to display an interstitial.
public void displayInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
横幅正常显示,间隙没有显示,并且日志猫也没有任何重要意义。 感谢
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<supports-screens android:smallScreens="true"
android:normalScreens="true" android:largeScreens="true"
android:anyDensity="true" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:hardwareAccelerated="true"
>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent"/>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"
/>
答案 0 :(得分:2)
方法displayInterstitial()
负责显示插页式广告
在您要在
上展示广告的任何地方或事件中调用此方法例如在任何按钮的onclick
监听器中,它将显示
编辑,如果您想要在应用开始时展示广告,请尝试使用adslistener,如下所示
interstitial.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
@Override
public void onAdOpened() {
}
@Override
public void onAdFailedToLoad(int errorCode) {
}
});