Admob插页式广告

时间:2016-12-22 05:07:24

标签: android admob google-admob

我想在我的Android应用中使用非页内广告。但是我想让它在每10分钟后显示一次,因为在我的应用程序中没有暂停或等级。一旦用户登录将持续观看数小时。

1 个答案:

答案 0 :(得分:0)

使用处理程序。在int delay = 15000时计算并给出10分钟的延迟

  Handler h = new Handler();
int delay = 15000; //15 seconds
Runnable runnable;
@Override
protected void onStart() {
 //start handler as activity become visible

    h.postDelayed(new Runnable() {
        public void run() {
            //do something
      // Show your Admob Ad here and Refetch the ad else it wont be shown second time

    if (admnbInterstetial.isLoaded()) {
        admnbInterstetial.show();
    }
   AdRequest adRequest1 = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
            admnbInterstetial.loadAd(adRequest1);


            runnable=this;

            h.postDelayed(runnable, delay);
        }
    }, delay);

    super.onStart();
}

@Override
protected void onPause() {
    h.removeCallbacks(runnable); //stop handler when activity not visible
    super.onPause();
}

这应该可以解决问题