我想每隔一分钟显示一个插页式广告...谁能用示例代码解释一下...
谢谢 请
interstitialAds = new InterstitialAd(this, "Your_Pub_ID");
final AdRequest adRequest = new AdRequest();
interstitialAds.loadAd(adRequest);
interstitialAds.setAdListener(this);
我想每隔一分钟显示一个插页式广告...谁能用示例代码解释一下...
谢谢 请
interstitialAds = new InterstitialAd(this, "Your_Pub_ID");
final AdRequest adRequest = new AdRequest();
interstitialAds.loadAd(adRequest);
interstitialAds.setAdListener(this);
首先,这对您的用户来说将是非常糟糕的体验。我强烈反对它。
但是,如果您真的想激怒您的用户,那么类似:
final Runnable runanble = new Runnable() {
public void run() {
while (true) {
wait(60000);
runOnUiThread(intersitial.showAd());
interstitial.loadAd(new request());
}
}
};
编辑: 不要这样做。我收到 Admob 的回复,说这直接违反了他们的政策,并且会禁用您的帐户。
这违反了 admob 政策,他们也会禁止你,这对用户来说将是非常糟糕的体验。
编辑:政策链接(请参阅“ Repeated or recurring interstitials
”部分)- https://support.google.com/admob/answer/6201362?hl=en&ref_topic=2745287
有多种方式可以定期显示插页式广告。您可以在应用中添加代码,以便定期显示插页式广告。
准备广告();
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/
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
}
};
interstitialAd.setAdListener(new AdListener() {
public void onAdLoaded() {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
MainActivity.this.interstitialAd.show();
}
}, 5000);
} });
很简单。创建 Timertask 并每 60000 毫秒调度一次。但这对用户来说是糟糕的用户体验。不要这样做
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);