我正在使用Facebook Audience Network并根据此article
我不会缓存广告,但广告会保留在屏幕上而不会刷新。我正在加载所有广告,他们会一直在屏幕上停留,直到用户关闭该应用。
private void initializeAds() {
//ENABLE TESTING MODE
if (BuildConfig.DEBUG) {
AdSettings.addTestDevice("alksdfj");//For testing ads
}
//NATIVE AD
nativeAd = new NativeAd(this, "alksdjf");
nativeAd.setAdListener(new AdListener() {
@Override
public void onError(Ad ad, AdError adError) {
}
@Override
public void onAdLoaded(Ad ad) {
// Render the Native Ad Template
View adView = NativeAdView.render(MainActivity.this, nativeAd, NativeAdView.Type.HEIGHT_120);
LinearLayout nativeAdContainer = (LinearLayout) findViewById(R.id.native_ad_container);
// Add the Native Ad View to your ad container
nativeAdContainer.addView(adView);
}
@Override
public void onAdClicked(Ad ad) {
}
@Override
public void onLoggingImpression(Ad ad) {
}
});
//BANNER AD
// Instantiate an AdView view
adView = new AdView(this, "alksdjf", AdSize.BANNER_HEIGHT_50);
// Find the Ad Container
LinearLayout adContainer = (LinearLayout) findViewById(R.id.banner_container);
// Add the ad view to your activity layout
adContainer.addView(adView);
//Interstitial AD
interstitialAd = new InterstitialAd(this, "alskdfj");
// Set listeners for the Interstitial Ad
interstitialAd.setAdListener(new InterstitialAdListener() {
@Override
public void onInterstitialDisplayed(Ad ad) {
// Interstitial displayed callback
}
@Override
public void onInterstitialDismissed(Ad ad) {
// Interstitial dismissed callback
}
@Override
public void onError(Ad ad, AdError adError) {
// Ad error callback
/*Toast.makeText(MainActivity.this, "Error: " + adError.getErrorMessage(),
Toast.LENGTH_LONG).show();*/
Log.d("FACEBOOK_ADS", adError.getErrorMessage());
}
@Override
public void onAdLoaded(Ad ad) {
// Show the ad when it's done loading.
}
@Override
public void onAdClicked(Ad ad) {
// Ad clicked callback
}
@Override
public void onLoggingImpression(Ad ad) {
// Ad impression logged callback
}
});
// Request an ad
nativeAd.loadAd();
adView.loadAd();
// For auto play video ads, it's recommended to load the ad
// at least 30 seconds before it is shown
interstitialAd.loadAd();
//interstitialAd.show();
}
这些广告可以在那里停留很长时间。此外,我正在使用已加载的插页式广告,但仅在用户解锁其设备时向用户显示。 (用户可能需要数小时才能解锁他们的设备)
我希望在这种情况下,这些广告会产生收入,还是我需要在一段时间后重新请求广告,例如缓存广告。
此外,BannerAds还具有刷新间隔设置。这会自动刷新广告还是我需要刷新它们