问题描述
我在使用适用于 Android 的 admob 的插页式广告方面遇到问题,即使我点击主页按钮或转到后台,商业视频仍在播放.有没有人知道如何解决这个问题?
I have an issues with interstitial ad using admob for Android, which is the commercial video still running even I tap home button or goes to background. Is there anyone knows how to fix this issue?
我已经搜索了一整天,但找不到它.有人说我们无法控制广告.但是当我们点击设备上的主页按钮或应用程序进入后台时,Youtube android 应用程序能够暂停.
I've searched all day long, but couldn't find it. Some says that we can't control the ad. But when Youtube android application is able to pause whenever we tap on Home Button on device or the app goes to background.
推荐答案
您使用的是什么版本的 AdMob SDK?此解决方案适用于 Google Play 服务.
What version of the AdMob SDK are you using? This solution will work with Google Play Services.
假设这是您设置插页式广告的方式:
Lets say that this is how you setup your interstitial:
//Here is where you setup your interstitial
//...
adView.setAdListener(new AdListener() {
@Override
public void onAdLoaded(){
adView.show();
}
});
在您的 onPause() 方法中,您可以执行以下操作:
In your onPause() method you can do the following:
protected void onPause() {
super.onPause();
if(adView != null) {
adView.setAdListener(null);
}
}
之所以有效,是因为当 onPause 方法因新的插页式广告而被调用时,广告已经处于展示过程中并且会正常展示.但是,如果由于其他原因(例如按下 Home 按钮)调用 onPause(),它将禁止显示新的插页式广告.
This works because by the time the onPause method is called because of a new interstitial, the ad will already be in the process of being shown and will display normally. However, if onPause() is called because of something else, like the Home button being pressed, it will disable new interstitials from being shown.
唯一需要注意的是,如果您使用的是 AdListener 提供的其他回调方法.
Only caveat is if you're using other callback methods available from the AdListener.
这篇关于Android应用程序进入后台时如何暂停插页式广告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!