This is the code for when I use native express ads (working)
RelativeLayout mAdView = (RelativeLayout)findViewById(R.id.adView);
NativeExpressAdView adObj = new NativeExpressAdView(this);
adObj.setAdUnitId(getResources().getString(R.string.native_ad_unit_id));
adObj.setAdSize(new AdSize(800,800));
mAdView.addView(adObj);
AdRequest request = new AdRequest.Builder().build();
adObj.loadAd(request);
And this code is for when I use interstitial ads (working)
InterstitialAd adObj = new InterstitialAd(this);
adObj.setAdUnitId(getResources().getString(R.string.interstitial_ad_id));
AdRequest request = new AdRequest.Builder().build();
adObj.loadAd(request);
adObj.show();
Can I use Interstitial ads like native express, not pop up just on layout?
非页内广告的主要功能是在布局上展示广告,但如果您想要弹出广告,请使用其他广告
InterstitialAd interstitialAd;
public void show(Context context) {
interstitialAd = new InterstitialAd(context);
interstitialAd.setAdUnitId(context.getResources().getString(R.string.id_ad_interstitial));
AdRequest adRequest = new AdRequest.Builder().build();
interstitialAd.loadAd(adRequest);
interstitialAd.setAdListener(new AdListener() {
public void onAdLoaded() {
// Call displayInterstitial() function
displayInterstitial();
}
});
}
public void displayInterstitial() {
// If Ads are loaded, show Interstitial else show nothing.
if (interstitialAd.isLoaded()) {
interstitialAd.show();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.