com.google.android.gms.ads.InterstitialAd Java Examples

The following examples show how to use com.google.android.gms.ads.InterstitialAd. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GooglePlayServicesInterstitial.java    From mobile-sdk-android with Apache License 2.0 6 votes vote down vote up
@Override
public void requestAd(MediatedInterstitialAdViewController mIC, Activity activity,
                      String parameter, String adUnitId, TargetingParameters targetingParameters) {
    adListener = new GooglePlayAdListener(mIC, super.getClass().getSimpleName());
    adListener.printToClog(String.format(" - requesting an ad: [%s, %s]", parameter, adUnitId));

    interstitialAd = new InterstitialAd(activity);
    interstitialAd.setAdUnitId(adUnitId);
    interstitialAd.setAdListener(adListener);

    try {
        interstitialAd.loadAd(buildRequest(targetingParameters));
    } catch (NoClassDefFoundError e) {
        // This can be thrown by Play Services on Honeycomb.
        adListener.onAdFailedToLoad(AdRequest.ERROR_CODE_NO_FILL);
    }
}
 
Example #2
Source File: MainActivity.java    From USB_Mass_Storage_Enabler with MIT License 6 votes vote down vote up
void initADs() {

		if(enableADs) {
			//https://firebase.google.com/docs/admob/android/quick-start
			MobileAds.initialize(getApplicationContext(), getString(R.string.ad_app_id));
			AdView mAdView = (AdView) findViewById(R.id.adView);
			AdRequest adRequest = new AdRequest.Builder().build();
			mAdView.loadAd(adRequest);
			Log.d(LOG_TAG, "Ads initialized..");

			mInterstitialAd = new InterstitialAd(this);
			mInterstitialAd.setAdUnitId(getString(R.string.interstitial_ad_unit_id));
			mInterstitialAd.setAdListener(new AdListener() {
				@Override
				public void onAdClosed() {
					//requestNewInterstitial();
				}
			});

			requestNewInterstitial();
		}
	}
 
Example #3
Source File: AdsManager.java    From text_converter with GNU General Public License v3.0 6 votes vote down vote up
public static void showFullScreenAdsIfRequired(final StateActivity activity) {
    if (Premium.isPremiumUser(activity)) return;
    final InterstitialAd interstitialAd = new InterstitialAd(activity.getApplicationContext());
    interstitialAd.setAdUnitId(AdConstants.AdUnitId.AD_UNIT_ID_INTERSTITIAL);
    AdRequest.Builder request = new AdRequest.Builder();
    if (BuildConfig.DEBUG) {
        request.addTestDevice(TEST_DEVICE_ID);
    }
    interstitialAd.loadAd(request.build());
    interstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            if (!activity.isFinishing() && activity.isActivityVisible()
                    && !Premium.isPremiumUser(activity)) {
                interstitialAd.show();
            }
        }
    });
}
 
Example #4
Source File: PlaceholderFragment.java    From android-gradle-java-app-template with Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                         @Nullable Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    final View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    startInterstitial = rootView.findViewById(R.id.buttonStartInterstitial);
    startInterstitial.setOnClickListener(onClickListener);

    adView = rootView.findViewById(R.id.adView);
    adView.setAdListener(adListener);
    adView.loadAd(new AdRequest.Builder().build());

    interstitialAd = new InterstitialAd(rootView.getContext());
    interstitialAd.setAdUnitId(getString(R.string.app_ad_interstitial));
    interstitialAd.setAdListener(adListener);
    interstitialAd.loadAd(new AdRequest.Builder().build());

    return rootView;
}
 
Example #5
Source File: HackChatInterstitialAd.java    From hack.chat-android with MIT License 6 votes vote down vote up
/**
 * Sets up the interstitial ad object.
 */
private void setUpInterstitialAd() throws Exception {
    if (!(advertable instanceof  Activity)) {
        throw new Exception("Only Activity class can implement HackChatInterstitialAdvertable.");
    }
    interstitialAd = new InterstitialAd((Activity) advertable);
    interstitialAd.setAdUnitId(adUnitId);

    interstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            advertable.onInterstitialAdClosed();
        }
    });

    requestInterstitialAd();
}
 
Example #6
Source File: FragmentLocationActivity.java    From GooglePlayServiceLocationSupport with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fragment_location);
    mInterstitialAd = new InterstitialAd(this);
    mInterstitialAd.setAdUnitId(getResources().getString(R.string.interstitial_ad));
    mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            finish();
        }
    });
    AdRequest adRequest = new AdRequest.Builder().build();
    mInterstitialAd.loadAd(adRequest);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
}
 
Example #7
Source File: HomeFragment.java    From Android with MIT License 6 votes vote down vote up
private void Ads(View v) {
    //adView = view.findViewById(R.id.adView);
    View adContainer = v.findViewById(R.id.adMobView);
   // Log.e("TAG :BANNERhomefragment",ADMOB_PLEX_BANNER_1);

    AdView mAdView = new AdView(mContext);
    mAdView.setAdSize(AdSize.SMART_BANNER);
    mAdView.setAdUnitId(ADMOB_PLEX_BANNER_1);
    ((RelativeLayout)adContainer).addView(mAdView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
    mInterstitialAd = new InterstitialAd(getActivity());
    mInterstitialAd.setAdUnitId(ADMOB_PLEX_INTERSTITIAL_1);
    mInterstitialAd.loadAd(new AdRequest.Builder().build());
    mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {

        }
    });

}
 
Example #8
Source File: SongBroadCast.java    From YTPlayer with GNU General Public License v3.0 6 votes vote down vote up
void showAd(Context con) {
    if (AppSettings.playAdCount%AppSettings.adOffset==0 && AppSettings.playAdCount!=0 && AppSettings.showAds) {
        Log.e(TAG, "showAd: Showing Ad..." );
        //TODO: Change ad unit ID, Sample ca-app-pub-3940256099942544/1033173712
        mInterstitialAd = new InterstitialAd(con);
        mInterstitialAd.setAdUnitId("ca-app-pub-1164424526503510/4801416648");
        mInterstitialAd.loadAd(new AdRequest.Builder().build());
        mInterstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdFailedToLoad(int i) {
                super.onAdFailedToLoad(i);
                Log.e(TAG, "onAdFailedToLoad: Ad failed to load: " + i);
            }

            @Override
            public void onAdLoaded() {
                super.onAdLoaded();
                mInterstitialAd.show();
            }
        });
    }
}
 
Example #9
Source File: PlayerActivity2.java    From YTPlayer with GNU General Public License v3.0 6 votes vote down vote up
public static void showAd() {
    if (!AppSettings.showAds)
        return;
    //TODO: Change ad unit ID, Sample ca-app-pub-3940256099942544/1033173712
    mInterstitialAd = new InterstitialAd(activity);
    mInterstitialAd.setAdUnitId("ca-app-pub-1164424526503510/4801416648");
    mInterstitialAd.loadAd(new AdRequest.Builder().addTestDevice("07153BA64BB64F7C3F726B71C4AE30B9").build());
    mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdFailedToLoad(int i) {
            super.onAdFailedToLoad(i);
            Log.e(TAG, "onAdFailedToLoad: Ad failed to load: " + i);
        }

        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            mInterstitialAd.show();
        }
    });
}
 
Example #10
Source File: GADManager.java    From Android-Plugin-Framework with MIT License 6 votes vote down vote up
private void initAD(){
    mInterstitialAd = new InterstitialAd(context);
    mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
    mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            requestNewInterstitial();
        }

        @Override
        public void onAdLoaded() {
            super.onAdLoaded();

            Toast.makeText(context, "广告加载完成, 点击show按钮显示广告", Toast.LENGTH_LONG).show();

            Log.e("tag","onAdLoaded");
        }
    });
    requestNewInterstitial();
}
 
Example #11
Source File: YTutils.java    From YTPlayer with GNU General Public License v3.0 6 votes vote down vote up
public static void showAd(Context con) {

        try {
            InterstitialAd mInterstitialAd = new InterstitialAd(con);
            mInterstitialAd.setAdUnitId("ca-app-pub-1164424526503510/4801416648");
            mInterstitialAd.loadAd(new AdRequest.Builder().addTestDevice("07153BA64BB64F7C3F726B71C4AE30B9").build());
            mInterstitialAd.setAdListener(new AdListener() {
                @Override
                public void onAdFailedToLoad(int i) {
                    super.onAdFailedToLoad(i);
                    Log.e(TAG, "onAdFailedToLoad: Ad failed to load: " + i);
                }

                @Override
                public void onAdLoaded() {
                    super.onAdLoaded();
                    mInterstitialAd.show();
                }
            });
        } catch (Exception ignored) {
        }
    }
 
Example #12
Source File: YTutils.java    From YTPlayer with GNU General Public License v3.0 6 votes vote down vote up
public static void showInterstitialAd(Context activity) {
    if (!AppSettings.showAds)
        return;
    //TODO: Change ad unit ID, Sample ca-app-pub-3940256099942544/1033173712
    InterstitialAd mInterstitialAd = new InterstitialAd(activity);
    mInterstitialAd.setAdUnitId("ca-app-pub-1164424526503510/4801416648");
    mInterstitialAd.loadAd(new AdRequest.Builder().addTestDevice("07153BA64BB64F7C3F726B71C4AE30B9").build());
    mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdFailedToLoad(int i) {
            super.onAdFailedToLoad(i);
            Log.e(TAG, "onAdFailedToLoad: Ad failed to load: " + i);
        }

        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            mInterstitialAd.show();
        }
    });
}
 
Example #13
Source File: AdMobManager.java    From ANEAdMob with Apache License 2.0 6 votes vote down vote up
public void cacheInterstitial(String adID, String testDevice)
{
	//Log.d("SOLITAIRE", "CACHE");
	
	_interstitial = new InterstitialAd(_act);
	_interstitial.setAdUnitId(adID);

	AdRequest adRequest = null;
	if(testDevice == null) //no test device
		adRequest = new AdRequest.Builder().build();
	else
		adRequest = new AdRequest.Builder().addTestDevice(testDevice).build(); //eto pizdec
	
	_interstitial.loadAd(adRequest);
	_interstitial.setAdListener(new AdMobListener(_ctx, "INTERSTITIAL"));
}
 
Example #14
Source File: MainActivity.java    From Instagram-Profile-Downloader with MIT License 6 votes vote down vote up
private void loadFbFullscreenAd() {
    if (mInterstitialFbAd != null) {
        if (!isFbAdsLoading && !mInterstitialFbAd.isAdLoaded()) {
            mInterstitialFbAd.loadAd();
            isFbAdsLoading = true;
            Log.e(TAG, "loadFbFullscreenAd: " + "Request");
        }

        Log.e(TAG, "loadFbFullscreenAd: " + "Requesting");
        return;
    }

    mInterstitialFbAd = new com.facebook.ads.InterstitialAd(MainActivity.this, getString(R.string.facebook_interstitial));
    mInterstitialFbAd.setAdListener(this);
    mInterstitialFbAd.loadAd();
    isFbAdsLoading = true;
}
 
Example #15
Source File: InterstitialAdActivity.java    From Instagram-Profile-Downloader with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_interstitial_ad);

    mInterstitialAd = new InterstitialAd(this);

    // set the ad unit ID
    mInterstitialAd.setAdUnitId("ca-app-pub-7814549536543810/9305872827");

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

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

    mInterstitialAd.setAdListener(new AdListener() {
        public void onAdLoaded() {
            showInterstitial();
        }
    });
}
 
Example #16
Source File: MainActivity.java    From BusyBox with Apache License 2.0 5 votes vote down vote up
private void showTabInterstitials() {
    if (interstitialsTabAd != null) {
        for (InterstitialAd interstitialAd : interstitialsTabAd) {
            if (interstitialIsReady(interstitialAd)) {
                interstitialAd.show();
                return;
            }
        }
    }
}
 
Example #17
Source File: MainActivity.java    From BusyBox with Apache License 2.0 5 votes vote down vote up
private void showSettingsInterstitials() {
    if (interstitialsSettingsAd != null) {
        for (InterstitialAd interstitialAd : interstitialsSettingsAd) {
            if (interstitialIsReady(interstitialAd)) {
                interstitialAd.show();
                return;
            }
        }
        startActivity(new Intent(this, SettingsActivity.class));
    }
}
 
Example #18
Source File: MainActivity.java    From BusyBox with Apache License 2.0 5 votes vote down vote up
private void showInstallInterstitials() {
    if (interstitialsInstallAd != null) {
        for (InterstitialAd interstitialAd : interstitialsInstallAd) {
            if (interstitialIsReady(interstitialAd)) {
                interstitialAd.show();
                Analytics.newEvent("interstitial_ad").put("id", interstitialAd.getAdUnitId()).log();
                return;
            }
        }
    }
}
 
Example #19
Source File: MainActivity.java    From BusyBox with Apache License 2.0 5 votes vote down vote up
private InterstitialAd newInterstitialAd(String placementId, AdListener listener) {
    InterstitialAd interstitialAd = new InterstitialAd(this);
    interstitialAd.setAdListener(listener);
    interstitialAd.setAdUnitId(placementId);
    interstitialAd.loadAd(getAdRequest());
    return interstitialAd;
}
 
Example #20
Source File: GenerateShortcutHelper.java    From TvAppRepo with Apache License 2.0 5 votes vote down vote up
static InterstitialAd showVisualAd(Activity activity) {
    final InterstitialAd video =  new InterstitialAd(activity);
    video.setAdUnitId(activity.getString(R.string.interstitial_ad_unit_id));
    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .build();
    video.loadAd(adRequest);
    Log.d(TAG, "Loading ad");

    video.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            Log.d(TAG, "Ad loaded");
            // Show video as soon as possible
            video.show();
        }

        @Override
        public void onAdClosed() {
            super.onAdClosed();
            Log.d(TAG, "Ad closed");
        }
    });

    return video;
}
 
Example #21
Source File: MainActivity.java    From BusyBox with Apache License 2.0 5 votes vote down vote up
private void showInstallInterstitials() {
    if (interstitialsInstallAd != null) {
        for (InterstitialAd interstitialAd : interstitialsInstallAd) {
            if (interstitialIsReady(interstitialAd)) {
                interstitialAd.show();
                Analytics.newEvent("interstitial_ad").put("id", interstitialAd.getAdUnitId()).log();
                return;
            }
        }
    }
}
 
Example #22
Source File: PlayActivity.java    From FixMath with Apache License 2.0 5 votes vote down vote up
void setupIntersitialAds(final int levelActual){
    if(levelActual % 2 == 0) {
        AdRequest adRequest = new AdRequest.Builder()
                .build();

        intersitialAdOnNextLevel = new InterstitialAd(this);
        intersitialAdOnNextLevel.setAdUnitId(getString(R.string.adID));
        intersitialAdOnNextLevel.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {

                showNextLevelOrClose(levelActual);
            }
        });
        intersitialAdOnNextLevel.loadAd(adRequest);

        intersitialAdOnClosed = new InterstitialAd(this);
        intersitialAdOnClosed.setAdUnitId(getString(R.string.adID));
        intersitialAdOnClosed.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
                Intent i = new Intent(PlayActivity.this, LevelMenuActivity.class);
                startActivity(i);
                finish();
            }
        });
        intersitialAdOnClosed.loadAd(adRequest);
    }
}
 
Example #23
Source File: PlayActivity.java    From FixMath with Apache License 2.0 5 votes vote down vote up
boolean showIntersitialAdOnNextLevel(InterstitialAd intersitialAdOnNextLevel, int actualLevel) {
    if (actualLevel % 2 == 0) {
        if (intersitialAdOnNextLevel.isLoaded()) {
            intersitialAdOnNextLevel.show();
            return true;
        } else {
            return false;
        }
    }else{
        return false;
    }


}
 
Example #24
Source File: PlayActivity.java    From FixMath with Apache License 2.0 5 votes vote down vote up
boolean showIntersitialAdOnClose(InterstitialAd intersitialAdOnClose, int actualLevel){
    if(actualLevel % 2 == 0) {
        if (intersitialAdOnClose.isLoaded()) {
            intersitialAdOnClose.show();
            return true;
        } else {
            return false;
        }
    }else{
        return false;
    }
}
 
Example #25
Source File: TimeAttackActivity.java    From FixMath with Apache License 2.0 5 votes vote down vote up
void setupIntersitialAds(){

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

            intersitialAdOnRepeat = new InterstitialAd(this);
            intersitialAdOnRepeat.setAdUnitId(getString(R.string.adID));
            intersitialAdOnRepeat.setAdListener(new AdListener() {
                @Override
                public void onAdClosed() {
                    repeatGame();
                }
            });
            intersitialAdOnRepeat.loadAd(adRequest);

            intersitialAdOnClosed = new InterstitialAd(this);
            intersitialAdOnClosed.setAdUnitId(getString(R.string.adID));
            intersitialAdOnClosed.setAdListener(new AdListener() {
                @Override
                public void onAdClosed() {
                    Intent i = new Intent(TimeAttackActivity.this, ChooseTimeChallenge.class);
                    startActivity(i);
                    finish();
                }
            });
            intersitialAdOnClosed.loadAd(adRequest);

    }
 
Example #26
Source File: TimeAttackActivity.java    From FixMath with Apache License 2.0 5 votes vote down vote up
boolean showIntersitialAdOnClose(InterstitialAd intersitialAdOnClose, boolean isShowInterstialOnClose){
        if(isShowInterstialOnClose) {
            if (intersitialAdOnClose.isLoaded()) {
                intersitialAdOnClose.show();
                return true;
            } else {
                return false;
            }
        }else {
            return false;
        }
}
 
Example #27
Source File: TimeAttackActivity.java    From FixMath with Apache License 2.0 5 votes vote down vote up
boolean showIntersitialAdOnNextLevel(InterstitialAd intersitialAdOnClose){
    if (intersitialAdOnClose.isLoaded()) {
        intersitialAdOnClose.show();
        return true;
    } else {
        return false;
    }
}
 
Example #28
Source File: BaseAdsActivity.java    From twoh-android-material-design with MIT License 5 votes vote down vote up
protected void initInterstitial(){
    interstitialAd = new InterstitialAd(this);
    interstitialAd.setAdUnitId(getString(R.string.interstitial_ad_unit_id));

    interstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            loadInterstitial();
        }
    });

    loadInterstitial();
}
 
Example #29
Source File: MyActivity.java    From googleads-mobile-android-examples with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);

    // Initialize the Mobile Ads SDK.
    MobileAds.initialize(this, new OnInitializationCompleteListener() {
        @Override
        public void onInitializationComplete(InitializationStatus initializationStatus) {}
    });

    // Create the InterstitialAd and set the adUnitId.
    interstitialAd = new InterstitialAd(this);
    // Defined in res/values/strings.xml
    interstitialAd.setAdUnitId(AD_UNIT_ID);

    interstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            Toast.makeText(MyActivity.this, "onAdLoaded()", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            Toast.makeText(MyActivity.this,
                    "onAdFailedToLoad() with error code: " + errorCode,
                    Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdClosed() {
            startGame();
        }
    });

    // Create the "retry" button, which tries to show an interstitial between game plays.
    retryButton = findViewById(R.id.retry_button);
    retryButton.setVisibility(View.INVISIBLE);
    retryButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showInterstitial();
        }
    });

    startGame();
}
 
Example #30
Source File: AdMobPlugin.java    From cordova-admob-pro with MIT License 5 votes vote down vote up
@Override
protected void __destroyInterstitial(Object interstitial) {
  if(interstitial == null) return;

  if(interstitial instanceof InterstitialAd) {
    InterstitialAd ad = (InterstitialAd) interstitial;
    ad.setAdListener(null);
  }
}