插屏 Interstitial 广告样式
优质
小牛编辑
132浏览
2023-12-01
插屏(Interstitial)
1. 确定SDK文件已经全部拷贝到工程文件的libs子目录下参考
2. 添加广告代码,添加广告代码前请确定已初始化SDK
- 注意:接入插屏广告要求媒体targetSdkVersion<27,否则自己用按原生广告代替插屏接入
例如:
private InterstitialAd mInterstitialAd; mInterstitialAd = new InterstitialAd(this, false); mInterstitialAd.setAdUnitId(adUnitId); // 设置广告位ID mInterstitialAd.setAdListener(new AdListener() { @Override public void onAdClosed() { Log.i("lance", "onAdClosed"); } @Override public void onAdClicked() { super.onAdClicked(); Log.i("lance", "onAdClicked"); } @Override public void onAdFailedToLoad(int errorCode) { super.onAdFailedToLoad(errorCode); Log.i("lance", "onAdFailedToLoad"); } @Override public void onAdShown() { super.onAdShown(); Log.i("lance", "onAdShown"); } @Override public void onAdLoaded() { super.onAdLoaded(); Log.i("lance", "onAdLoaded"); if (mInterstitialAd != null && mInterstitialAd.isLoaded()) { mInterstitialAd.show(); } } }); if (!mInterstitialAd.isLoading() && !mInterstitialAd.isLoaded()) { AdRequest adRequest = new AdRequest.Builder().build(); mInterstitialAd.loadAd(adRequest); } //需要销毁资源 @Override protected void onDestroy() { mInterstitialAd.cancel(); super.onDestroy(); }
PS:更多设置请参考Demo中的com.hubcloud.adhubsdkdemo.InterstitialActivity的代码.