我在我的应用中添加了插页式广告(+横幅),其中包含一项活动,横幅广告没有问题,但插页式广告仅在应用启动时显示,我的应用不包含任何按钮或操作只是pdfview我想要做的是在用户阅读pdf时每5分钟显示一次广告。我搜索了类似的问题,但无法得到它。这里我的代码加载并显示广告:
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
// Prepare the Interstitial Ad
interstitial = new InterstitialAd(PDFViewActivity.this);
// Insert the Ad Unit ID
interstitial.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
interstitial.loadAd(adRequest);
// Prepare an Interstitial Ad Listener
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
// Call displayInterstitial() function
displayInterstitial();
}
});
}
public void displayInterstitial() {
// If Ads are loaded, show Interstitial else show nothing.
if (interstitial.isLoaded()) {
interstitial.show();
}
}
答案 0 :(得分:1)
我是这样做的:
position:fixed
答案 1 :(得分:0)
好的,所以你试图定期显示插页式广告。那么你可以使用下面的代码来完成它。
然而,这违反了Google admob政策。但是你走了。
在mainactiviy.java中添加以下代码。
prepareAd();
ScheduledExecutorService scheduler =
Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleAtFixedRate(new Runnable() {
public void run() {
Log.i("hello", "world");
runOnUiThread(new Runnable() {
public void run() {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
Log.d("TAG"," Interstitial not loaded");
}
prepareAd();
}
});
}
}, 20, 20, TimeUnit.SECONDS);
然后在MainActivity.java的最后一个大括号
之前添加以下代码行public void prepareAd(){
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-39xxx560xxxxxxx/10331xxxxx");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
}
public void prepareAd(){
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-39xxx560xxxxxxx/10331xxxxx");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
}
此处使用的非页内AdMob ID是一个示例ID。代码取自http://www.elegantespace.com/how-to-load-interstitial-ad-at-regular-interval-of-time/