Android 应用程序启动时的Admob间隙
我希望在用户首次打开应用程序或用户导航到另一个应用程序(如浏览器)然后返回到我的应用程序时显示admob中间广告。这是我当前的Intersital ad代码,该代码完全包含在OnCreate方法中Android 应用程序启动时的Admob间隙,android,admob,interstitial,Android,Admob,Interstitial,我希望在用户首次打开应用程序或用户导航到另一个应用程序(如浏览器)然后返回到我的应用程序时显示admob中间广告。这是我当前的Intersital ad代码,该代码完全包含在OnCreate方法中 // Create the interstitial. interstitial = new InterstitialAd(this); interstitial.setAdUnitId("ca-app-pub-XXXXXXXXXXXXXXXX");
// Create the interstitial.
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("ca-app-pub-XXXXXXXXXXXXXXXX");
// Create ad request.
AdRequest adRequest2 = new AdRequest.Builder().build();
// Begin loading your interstitial.
interstitial.loadAd(adRequest2);
interstitial.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
});
这似乎适用于大多数情况,但在某些设备上,这将创建一个间隙循环,在用户关闭后显示2-3秒。其中一个具有环路的设备是Galaxy Tab3。我似乎无法找到一种正确的方法来设置我的代码,以便在任何设备上都不会发生这种行为 创建一个布尔变量来辅助它
boolean ad_shown = false;
执行此操作时,请将.show()变量设置为true
别忘了在if上加一个警卫
if (interstitial.isLoaded() && !ad_shown) {
创建一个布尔变量来辅助它
boolean ad_shown = false;
执行此操作时,请将.show()变量设置为true
别忘了在if上加一个警卫
if (interstitial.isLoaded() && !ad_shown) {
当应用程序启动时,使用以下代码显示间隙ad
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("***********");
AdRequest adRequest = new AdRequest.Builder().build();
interstitial.loadAd(adRequest);
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
displayInterstitial();
}
});
}
public void displayInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
当应用程序启动时,使用以下代码显示间隙ad
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("***********");
AdRequest adRequest = new AdRequest.Builder().build();
interstitial.loadAd(adRequest);
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
displayInterstitial();
}
});
}
public void displayInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}