【问题标题】:How to load facebook ads after certain time of app load?应用程序加载一定时间后如何加载 Facebook 广告?
【发布时间】:2020-12-18 17:04:07
【问题描述】:

您好,我正在创建一个 Android 应用。我想在应用加载一段时间后显示插页式广告。说 60 秒。

只要单击某个按钮或图标,我开发的代码就会立即添加,我需要它应该在延迟 60 秒后显示。但同时App应该执行点击操作,不应该等待或休眠。



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());
    }

}


帮助我解决我的问题。

【问题讨论】:

标签: java android facebook admob


【解决方案1】:

使用Handler来延迟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();
                   }
              });
                
            }

【讨论】:

  • 用这个替换 onAdLoaded 函数。
猜你喜欢
  • 1970-01-01
  • 2023-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-17
相关资源
最近更新 更多