显示初始屏幕图像并加载/显示插页式广告

时间:2018-08-29 23:48:21

标签: android android-studio admob interstitial

我希望在主屏幕之前将插页式广告集成到我的应用中 我怎样才能做到这一点? 这是我的MainActivity代码:

public class HomeMain extends AppCompatActivity {

private InterstitialAd mInterstitialAd;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home_main);

    mInterstitialAd = new InterstitialAd(this);

    //set the ad unit ID
    mInterstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));

    AdRequest adRequest = new AdRequest.Builder()
            .build();

    //Load ads into Interstitial Ads
    mInterstitialAd.loadAd(adRequest);

    mInterstitialAd.setAdListener(new AdListener() {
        public void onAdLoaded() {
            showInterstitial();
        }
    });
}

private void showInterstitial() {
    if (mInterstitialAd.isLoaded()) {
        mInterstitialAd.show();
    }

谢谢

0 个答案:

没有答案