我希望每隔一分钟后显示插页式广告... 任何人都可以用示例代码解释......
感谢 请
interstitialAds = new InterstitialAd(this, "Your_Pub_ID");
final AdRequest adRequest = new AdRequest();
interstitialAds.loadAd(adRequest);
interstitialAds.setAdListener(this);
答案 0 :(得分:8)
首先,这将为您的用户带来非常糟糕的体验。我强烈建议不要这样做。
但是,如果你真的想要惹恼你的用户,那就是:
final Runnable runanble = new Runnable() {
public void run() {
while (true) {
wait(60000);
runOnUiThread(intersitial.showAd());
interstitial.loadAd(new request());
}
}
};
编辑: 不要这样做。我从Admob那里得到的消息是,这直接违反了他们的政策,并且会禁用您的帐户。
答案 1 :(得分:6)
这违反了admob政策,他们也会禁止你,这对用户来说也是非常糟糕的经历。
答案 2 :(得分:2)
有很多方法可以定期显示插页式广告。您可以在应用中添加代码,以便定期展示插页式广告。
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);
然而,我(你可以说那是admob)强烈阻止你做这些事情。这违反了AdMob政策,如果您这样做,您的帐户将被暂停。
如果您想了解更多关于Android应用开发的内容以及如何在您的应用中放置admob广告。我建议你访问这个网站。
http://www.elegantespace.com/how-to-load-interstitial-ad-at-regular-interval-of-time/
答案 3 :(得分:1)
place it in oncreate method
handler.postDelayed(runnable, 420000);
在oncreate方法之后
Runnable runnable = new Runnable(){
@Override
public void run() {
// TODO Auto-generated method stub
//Your code to show add
// Create the interstitial.
// Prepare the Interstitial Ad
Interstitial = new InterstitialAd(your activity);
// Insert the Ad Unit ID
interstitial.setAdUnitId("your id ");
//Locate the Banner Ad in activity_main.xml
AdView adView = (AdView) findViewById(R.id.ad_view);
// Request for Ads
AdRequest adRequest = new AdRequest.Builder()
// Add a test device to show Test Ads
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("")
.build();
// Load ads into Banner Ads
adView.loadAd(adRequest);
// Load ads into Interstitial Ads
Interstitial.loadAd(adRequest);
// Prepare an Interstitial Ad Listener
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
// Call displayInterstitial() function
displayInterstitial();
}
});
handler.postDelayed(this, 600000); // 1000 - Milliseconds
}
};
答案 4 :(得分:1)
{{1}}
答案 5 :(得分:1)
final Handler handler = new Handler();
Timer timer = new Timer();
TimerTask doAsynchronousTask = new TimerTask() {
@Override
public void run() {
handler.post(new Runnable() {
public void run() {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}
});
}
};
timer.schedule(doAsynchronousTask, 0, 60000);