【发布时间】:2020-08-25 07:14:33
【问题描述】:
我想在我的 Android 应用中使用 Facebook Audience Network,我在应用内集成了 interstitialAd,它运行良好,但它显示为 Activity 启动。我想在 30 秒后展示广告。这是我的代码
interstitialAd = new InterstitialAd(this, "1555910157949688_1556058954601475");
interstitialAd.setAdListener(new InterstitialAdListener() {
@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();
}
});
interstitialAd.loadAd();
我已经尝试这样做来安排我的广告,但它不起作用。
private void showAdWithDelay() {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
// Check if interstitialAd has been loaded successfully
if(interstitialAd == null || !interstitialAd.isAdLoaded()) {
return;
}
// Check if the ad is already expired or invalidated, and do not show ad if that is the case. You will not get paid to show an invalidated ad.
if(interstitialAd.isAdInvalidated()) {
return;
}
// Show the ad
interstitialAd.show();
}
}, 3000);
}
【问题讨论】:
-
您使用了 3000,即 3 秒,请使用 30 * 1000 持续 30 秒
-
是的,我使用的是 30000,这是个问题
-
我建议您将 interstitialAd 对象实例化为 25 秒或 30 秒,因为有时它取决于网络,广告会延迟 3-4 秒显示
标签: android-studio handler android-handler interstitial facebook-audience-network