我正在尝试向应用程序添加Admob插页式广告。我将屏幕保持水平,但广告却弹出了几次。这是非常令人反感的情况。我怎样才能解决这个问题?谢谢。
public class MainActivity extends Activity {
private InterstitialAd mInterstitialAd;
private AdRequest adRequest;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
adRequest = new AdRequest.Builder().build();
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-xxxxxxxxx");
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded(){
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}
});
mInterstitialAd.loadAd(adRequest);
}}
最佳答案
为了澄清起见,您实际上可以在运行时加载广告,但您不应在运行时显示广告。
例如,您可以在下载完成后展示广告,然后可以调用mInterstitialAd.isLoaded()
方法进行展示。
mInterstitialAd = new InterstitialAd(this);
adRequest = new AdRequest.Builder().build();
mInterstitialAd.setAdUnitId("ca-app-pub-xxxxxxxxx");
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded(){
//The ad is ready call it when the timing is right
}
});
mInterstitialAd.loadAd(adRequest);