private InterstitialAd interstitialAd;
private com.google.android.gms.ads.InterstitialAd mInterstitialAd;
onCreate
MobileAds.initialize(getActivity(), new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {}
});mInterstitialAd = new com.google.android.gms.ads.InterstitialAd(getActivity());
mInterstitialAd.setAdUnitId("ca-app-pub-3744018609707534/3930596177");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
onclick
StartAppAd.showAd(getActivity());
showAdWithDelay();
private void setfbInter() {
interstitialAd = new InterstitialAd(getActivity(), getString(R.string.interstitial_placement));
for load add
// load the ad
interstitialAd.loadAd();
}
private void showAdWithDelay() {
/**
* Here is an example for displaying the ad with delay;
* Please do not copy the Handler into your project
*/
// Handler handler = new Handler();
new Handler().postDelayed(new Runnable() {
public void run() {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
// Check if interstitialAd has been loaded successfully
if (interstitialAd == null || !interstitialAd.isAdLoaded()) {
StartAppAd.showAd(getActivity());
return;
}
// Check if ad is already expired or invalidated, and do not show ad if that is the case. You will not get paid to show an invalidated ad.
if (interstitialAd.isAdInvalidated()) {
StartAppAd.showAd(getActivity());
return;
}
// Show the ad
interstitialAd.show();
}
}
}, 200); // Show the ad after 15 minutes
}
Comments
Post a Comment