如何在应用加载一定时间后加载facebook广告?

qxsslcnc  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(380)

嗨,我正在创建一个android应用程序。我想显示后,一段时间的应用程序加载插页广告。比如说60秒。
我开发的代码显示添加立即一些按钮或图标是点击,我需要它应该显示后,比如说60秒的延迟。但与此同时,应用程序应该执行点击操作,不应该等待或睡眠。

public static void showFANInterstitialAds(Activity context) {
    final String TAG = "FAN";
    if (!PreferenceUtils.isActivePlan(context)) {
        DatabaseHelper db = new DatabaseHelper(context);
        String placementId = db.getConfigurationData().getAdsConfig().getFanInterstitialAdsPlacementId();

        final com.facebook.ads.InterstitialAd interstitialAd = new com.facebook.ads.InterstitialAd(context, placementId);
        InterstitialAdListener listener = new InterstitialAdListener() {
            @Override
            public void onInterstitialDisplayed(Ad ad) {
                // Interstitial ad displayed callback
                Log.e(TAG, "Interstitial ad displayed.");
            }

            @Override
            public void onInterstitialDismissed(Ad ad) {
                // Interstitial dismissed callback
                Log.e(TAG, "Interstitial ad dismissed.");
            }

            @Override
            public void onError(Ad ad, AdError adError) {
                // Ad error callback
                Log.e(TAG, "Interstitial ad failed to load: " + adError.getErrorMessage());
            }

            @Override
            public void onAdLoaded(Ad ad) {
                // Interstitial ad is loaded and ready to be displayed
                Log.d(TAG, "Interstitial ad is loaded and ready to be displayed!");
                // Show the ad
                interstitialAd.show();
            }

            @Override
            public void onAdClicked(Ad ad) {
                // Ad clicked callback
                Log.d(TAG, "Interstitial ad clicked!");
            }

            @Override
            public void onLoggingImpression(Ad ad) {
                // Ad impression logged callback
                Log.d(TAG, "Interstitial ad impression logged!");
            }
        };

        interstitialAd.loadAd(interstitialAd.buildLoadAdConfig()
                .withAdListener(listener)
                .build());
    }

}

帮我解决问题。

r55awzrz

r55awzrz1#

使用处理程序延迟show方法。

@Override
            public void onAdLoaded(Ad ad) {
                // Interstitial ad is loaded and ready to be displayed
                Log.d(TAG, "Interstitial ad is loaded and ready to be displayed!");
                // Show the ad
                new Handler().postDelayed(60000,new Runnable() {
                   @Override
                   public void run() {
                     interstitialAd.show();
                   }
              });

            }

相关问题