0

我想每隔一分钟显示一个插页式广告...谁能用示例代码解释一下...

谢谢 请

    interstitialAds = new InterstitialAd(this, "Your_Pub_ID");
    final AdRequest adRequest = new AdRequest();
    interstitialAds.loadAd(adRequest);
    interstitialAds.setAdListener(this);
4

6 回答 6

8

首先,这对您的用户来说将是非常糟糕的体验。我强烈反对它。

但是,如果您真的想激怒您的用户,那么类似:

final Runnable runanble = new Runnable() {
  public void run() {
    while (true) {
      wait(60000);
      runOnUiThread(intersitial.showAd());
      interstitial.loadAd(new request());
    }
  }
};

编辑: 不要这样做。我收到 Admob 的回复,说这直接违反了他们的政策,并且会禁用您的帐户。

于 2013-10-07T23:29:05.783 回答
7

这违反了 admob 政策,他们也会禁止你,这对用户来说将是非常糟糕的体验。

编辑:政策链接(请参阅“ Repeated or recurring interstitials”部分)- https://support.google.com/admob/answer/6201362?hl=en&ref_topic=2745287

于 2014-07-19T10:12:11.197 回答
4

有多种方式可以定期显示插页式广告。您可以在应用中添加代码,以便定期显示插页式广告。


准备广告();

    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/

于 2017-07-25T02:05:46.190 回答
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
 }
 };
于 2016-09-30T07:27:19.220 回答
1
interstitialAd.setAdListener(new AdListener() {
public void onAdLoaded() {
    Handler handler = new Handler(); 
    handler.postDelayed(new Runnable() { 
        public void run() { 
            MainActivity.this.interstitialAd.show();
        } 
    }, 5000);
} });
于 2017-04-03T20:36:42.043 回答
1

很简单。创建 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);
于 2017-06-10T04:08:47.720 回答