整合插页式广告并每隔X分钟显示一次 [英] Integrating Interstitial Ads and Show Every X Minute
本文介绍了整合插页式广告并每隔X分钟显示一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我成功地将 本 教程,我想问一下,如何每隔X分钟更改插页式广告
I have success integrate the interstitial ad from admob in my application from this tutorial, i want to ask, how to change interstitial ads every X minute
推荐答案
这违反了Google政策,但是如果您仍然想实施此政策
It is against google policy but if you still want to implement this
private void setUpInterstitialAd() {
interstitialAd = new InterstitialAd(this);
interstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
interstitialAd.loadAd(new AdRequest.Builder().build());
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
// Load the next interstitial.
interstitialAd.loadAd(new AdRequest.Builder().build());
}
});
}
private void scheduleInterstitial() {
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
displayInterstitial();
setUpInterstitialAd();
}
});
}
}, 1, 5, TimeUnit.MINUTES);
}
private void displayInterstitial() {
if (interstitialAd != null) {
if (interstitialAd.isLoaded()) {
interstitialAd.show();
}
}
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setUpInterstitialAd();
scheduleInterstitial();
}
这篇关于整合插页式广告并每隔X分钟显示一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文