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

The following examples show how to use com.google.android.gms.ads.AdListener. 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 Project: Instagram-Profile-Downloader   Author: beNitinhere   File: InterstitialAdActivity.java    License: 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 #2
Source Project: Instagram-Profile-Downloader   Author: beNitinhere   File: ViewStoryActivity.java    License: MIT License 6 votes vote down vote up
@Override
public void onBackPressed() {
    if (interstitialAd.isLoaded()) {
        interstitialAd.show();
        interstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
                super.onAdClosed();
                finish();
            }
        });
    } else {
        super.onBackPressed();
        finish();
        overridePendingTransition(R.anim.enter_signin, R.anim.exit_main);
    }

}
 
Example #3
Source Project: YTPlayer   Author: KaustubhPatange   File: YTutils.java    License: 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 #4
Source Project: YTPlayer   Author: KaustubhPatange   File: YTutils.java    License: 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 #5
Source Project: YTPlayer   Author: KaustubhPatange   File: PlayerActivity2.java    License: 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 #6
Source Project: YTPlayer   Author: KaustubhPatange   File: SongBroadCast.java    License: 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 #7
Source Project: Android   Author: PlexMediaInc   File: HomeFragment.java    License: 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 Project: text_converter   Author: tranleduy2000   File: AdsManager.java    License: 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 #9
Source Project: prebid-mobile-android   Author: prebid   File: DemoActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void setupAMInterstitial(String id) {
    amInterstitial = new PublisherInterstitialAd(this);
    amInterstitial.setAdUnitId(id);
    amInterstitial.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            amInterstitial.show();
        }

        @Override
        public void onAdFailedToLoad(int i) {
            super.onAdFailedToLoad(i);
            AlertDialog.Builder builder;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                builder = new AlertDialog.Builder(DemoActivity.this, android.R.style.Theme_Material_Dialog_Alert);
            } else {
                builder = new AlertDialog.Builder(DemoActivity.this);
            }
            builder.setTitle("Failed to load AdManager interstitial ad")
                    .setMessage("Error code: " + i)
                    .setIcon(android.R.drawable.ic_dialog_alert)
                    .show();
        }
    });
}
 
Example #10
Source Project: quickstart-android   Author: firebase   File: AdViewIdlingResource.java    License: Apache License 2.0 6 votes vote down vote up
public AdViewIdlingResource(AdView adView) {
    if (adView == null) {
        throw new IllegalArgumentException(
                "Can't initialize AdViewIdlingResource with null AdView.");
    }

    this.mAdView = adView;
    this.mAdListener = new AdListener() {
        @Override
        public void onAdFailedToLoad(int i) {
            transitionToIdle();
        }

        @Override
        public void onAdLoaded() {
            transitionToIdle();
        }
    };

    mAdView.setAdListener(mAdListener);
}
 
Example #11
Source Project: BusyBox   Author: jrummyapps   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void setupTabInterstitialsAd() {
    String[] ids = getResources().getStringArray(R.array.tabs_interstitials_id);

    for (int i = 0; i < interstitialsTabAd.length; i++) {
        if (!interstitialIsReady(interstitialsTabAd[i])) {
            final int finalI = i;

            AdListener adListener = new AdListener() {
                @Override public void onAdClosed() {
                    super.onAdClosed();
                    interstitialsTabAd[finalI] = null;
                    setupTabInterstitialsAd();
                }
            };

            interstitialsTabAd[i] = newInterstitialAd(ids[i], adListener);
        }
    }
}
 
Example #12
Source Project: BusyBox   Author: jrummyapps   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void setupSettingsInterstitialsAd() {
    String[] ids = getResources().getStringArray(R.array.settings_interstitials_id);

    for (int i = 0; i < interstitialsSettingsAd.length; i++) {
        if (!interstitialIsReady(interstitialsSettingsAd[i])) {
            final int finalI = i;

            AdListener adListener = new AdListener() {
                @Override public void onAdClosed() {
                    super.onAdClosed();
                    interstitialsSettingsAd[finalI] = null;
                    setupSettingsInterstitialsAd();
                    startActivity(new Intent(MainActivity.this, SettingsActivity.class));
                }
            };

            interstitialsSettingsAd[i] = newInterstitialAd(ids[i], adListener);
        }
    }
}
 
Example #13
Source Project: BusyBox   Author: jrummyapps   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void setupInstallInterstitialsAd() {
    String[] ids = getResources().getStringArray(R.array.install_interstitials_id);

    for (int i = 0; i < interstitialsInstallAd.length; i++) {
        if (!interstitialIsReady(interstitialsInstallAd[i])) {
            final int finalI = i;

            AdListener adListener = new AdListener() {
                @Override public void onAdClosed() {
                    super.onAdClosed();
                    interstitialsInstallAd[finalI] = null;
                    setupInstallInterstitialsAd();
                }
            };

            interstitialsInstallAd[i] = newInterstitialAd(ids[i], adListener);
        }
    }
}
 
Example #14
Source Project: BusyBox   Author: jrummyapps   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void setupTabInterstitialsAd() {
    String[] ids = getResources().getStringArray(R.array.tabs_interstitials_id);

    for (int i = 0; i < interstitialsTabAd.length; i++) {
        if (!interstitialIsReady(interstitialsTabAd[i])) {
            final int finalI = i;

            AdListener adListener = new AdListener() {
                @Override public void onAdClosed() {
                    super.onAdClosed();
                    interstitialsTabAd[finalI] = null;
                    setupTabInterstitialsAd();
                }
            };

            interstitialsTabAd[i] = newInterstitialAd(ids[i], adListener);
        }
    }
}
 
Example #15
Source Project: BusyBox   Author: jrummyapps   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void setupSettingsInterstitialsAd() {
    String[] ids = getResources().getStringArray(R.array.settings_interstitials_id);

    for (int i = 0; i < interstitialsSettingsAd.length; i++) {
        if (!interstitialIsReady(interstitialsSettingsAd[i])) {
            final int finalI = i;

            AdListener adListener = new AdListener() {
                @Override public void onAdClosed() {
                    super.onAdClosed();
                    interstitialsSettingsAd[finalI] = null;
                    setupSettingsInterstitialsAd();
                    startActivity(new Intent(MainActivity.this, SettingsActivity.class));
                }
            };

            interstitialsSettingsAd[i] = newInterstitialAd(ids[i], adListener);
        }
    }
}
 
Example #16
Source Project: BusyBox   Author: jrummyapps   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void setupInstallInterstitialsAd() {
    String[] ids = getResources().getStringArray(R.array.install_interstitials_id);

    for (int i = 0; i < interstitialsInstallAd.length; i++) {
        if (!interstitialIsReady(interstitialsInstallAd[i])) {
            final int finalI = i;

            AdListener adListener = new AdListener() {
                @Override public void onAdClosed() {
                    super.onAdClosed();
                    interstitialsInstallAd[finalI] = null;
                    setupInstallInterstitialsAd();
                }
            };

            interstitialsInstallAd[i] = newInterstitialAd(ids[i], adListener);
        }
    }
}
 
Example #17
Source Project: USB_Mass_Storage_Enabler   Author: GokulNC   File: MainActivity.java    License: 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 #18
Source Project: hack.chat-android   Author: RudraNirvan   File: HackChatInterstitialAd.java    License: 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 #19
Source Project: admobadapter   Author: clockbyte   File: AdmobFetcherExpress.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Subscribing to the native ads events
 * @param adView
 */
protected synchronized void setupAd(final NativeExpressAdView adView) {
    if(mFetchFailCount > MAX_FETCH_ATTEMPT)
        return;

    if(!mPrefetchedAds.contains(adView))
        mPrefetchedAds.add(adView);
    adView.setAdListener(new AdListener() {
        @Override
        public void onAdFailedToLoad(int errorCode) {
            super.onAdFailedToLoad(errorCode);
            // Handle the failure by logging, altering the UI, etc.
            onFailedToLoad(adView, errorCode);
        }
        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            onFetched(adView);
        }
    });
}
 
Example #20
Source Project: admobadapter   Author: clockbyte   File: AdmobFetcherBanner.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Subscribing to the banner ads events
 * @param adView
 */
protected synchronized void setupAd(final AdView adView) {
    if(mFetchFailCount > MAX_FETCH_ATTEMPT)
        return;

    if(!mPrefetchedAds.contains(adView))
        mPrefetchedAds.add(adView);
    adView.setAdListener(new AdListener() {
        @Override
        public void onAdFailedToLoad(int errorCode) {
            super.onAdFailedToLoad(errorCode);
            // Handle the failure by logging, altering the UI, etc.
            onFailedToLoad(adView, errorCode);
        }
        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            onFetched(adView);
        }
    });
}
 
Example #21
Source Project: Android-Plugin-Framework   Author: limpoxe   File: GADManager.java    License: 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 #22
Source Project: remixed-dungeon   Author: NYRDS   File: AdMobComboProvider.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void showInterstitial(final InterstitialPoint ret) {
    Game.instance().runOnUiThread(() -> {
        if (mInterstitialAd == null) {
            EventCollector.logException("mInterstitialAd == null");
            AdsUtilsCommon.interstitialFailed(AdMobComboProvider.this, ret);
            return;
        }

        if (!mInterstitialAd.isLoaded()) {
            EventCollector.logException("not loaded");
            AdsUtilsCommon.interstitialFailed(AdMobComboProvider.this, ret);
            return;
        }

        mInterstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
                requestNewInterstitial();
                ret.returnToWork(true);
            }
        });
        mInterstitialAd.show();
    });

}
 
Example #23
Source Project: Instagram-Profile-Downloader   Author: beNitinhere   File: StoriesFragment.java    License: MIT License 5 votes vote down vote up
private void loadNativeAds() {

        AdLoader.Builder builder = new AdLoader.Builder(context, getString(R.string.native_ad_id));
        adLoader = builder.forUnifiedNativeAd(
                new UnifiedNativeAd.OnUnifiedNativeAdLoadedListener() {
                    @Override
                    public void onUnifiedNativeAdLoaded(UnifiedNativeAd unifiedNativeAd) {
                        // A native ad loaded successfully, check if the ad loader has finished loading
                        // and if so, insert the ads into the list.
                        mNativeAds.add(unifiedNativeAd);
                        if (!adLoader.isLoading()) {
                            insertAdsInMenuItems();
                        }
                    }
                }).withAdListener(
                new AdListener() {
                    @Override
                    public void onAdFailedToLoad(int errorCode) {
                        // A native ad failed to load, check if the ad loader has finished loading
                        // and if so, insert the ads into the list.
                        Log.e("MainActivity", "The previous native ad failed to load. Attempting to"
                                + " load another.");
                        if (!adLoader.isLoading()) {
                            insertAdsInMenuItems();
                        }
                    }
                }).build();

        // Load the Native Express ad.
    }
 
Example #24
Source Project: Instagram-Profile-Downloader   Author: beNitinhere   File: StoriesFragment.java    License: MIT License 5 votes vote down vote up
private void loadNativeExpressAd(final int index) {

        if (index >= userObjectList.size()) {
            return;
        }

        Object item = userObjectList.get(index);
        if (!(item instanceof NativeExpressAdView)) {
            throw new ClassCastException("Expected item at index " + index + " to be a Native"
                    + " Express ad.");
        }

        final NativeExpressAdView adView = (NativeExpressAdView) item;

        // Set an AdListener on the NativeExpressAdView to wait for the previous Native Express ad
        // to finish loading before loading the next ad in the items list.
        adView.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                super.onAdLoaded();
                // The previous Native Express ad loaded successfully, call this method again to
                // load the next ad in the items list.
                loadNativeExpressAd(index + spaceBetweenAds + 1);
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                // The previous Native Express ad failed to load. Call this method again to load
                // the next ad in the items list.
                Log.e("AdmobMainActivity", "The previous Native Express ad failed to load. Attempting to"
                        + " load the next Native Express ad in the items list.");
                loadNativeExpressAd(index + spaceBetweenAds + 1);
            }
        });

        // Load the Native Express ad.
        //We also registering our device as Test Device with addTestDevic("ID") method
        adView.loadAd(new AdRequest.Builder().addTestDevice("ca-app-pub-3940256099942544/2247696110").build());
    }
 
Example #25
Source Project: Instagram-Profile-Downloader   Author: beNitinhere   File: StoriesOverview.java    License: MIT License 5 votes vote down vote up
private void loadNativeAds() {

        AdLoader.Builder builder = new AdLoader.Builder(context, getString(R.string.native_ad_id));
        adLoader = builder.forUnifiedNativeAd(
                new UnifiedNativeAd.OnUnifiedNativeAdLoadedListener() {
                    @Override
                    public void onUnifiedNativeAdLoaded(UnifiedNativeAd unifiedNativeAd) {
                        // A native ad loaded successfully, check if the ad loader has finished loading
                        // and if so, insert the ads into the list.
                        mNativeAds.add(unifiedNativeAd);
                        if (!adLoader.isLoading()) {
                            insertAdsInMenuItems();
                        }
                    }
                }).withAdListener(
                new AdListener() {
                    @Override
                    public void onAdFailedToLoad(int errorCode) {
                        // A native ad failed to load, check if the ad loader has finished loading
                        // and if so, insert the ads into the list.
                        Log.e("MainActivity", "The previous native ad failed to load. Attempting to"
                                + " load another.");
                        if (!adLoader.isLoading()) {
                            insertAdsInMenuItems();
                        }
                    }
                }).build();

        // Load the Native Express ad.
    }
 
Example #26
Source Project: Instagram-Profile-Downloader   Author: beNitinhere   File: DownloadHistoryPhotoFragment.java    License: MIT License 5 votes vote down vote up
private void loadNativeAds() {

        AdLoader.Builder builder = new AdLoader.Builder(context, getString(R.string.native_ad_id));
        adLoader = builder.forUnifiedNativeAd(
                new UnifiedNativeAd.OnUnifiedNativeAdLoadedListener() {
                    @Override
                    public void onUnifiedNativeAdLoaded(UnifiedNativeAd unifiedNativeAd) {
                        // A native ad loaded successfully, check if the ad loader has finished loading
                        // and if so, insert the ads into the list.
                        mNativeAds.add(unifiedNativeAd);
                        if (!adLoader.isLoading()) {
                            insertAdsInMenuItems();
                        }
                    }
                }).withAdListener(
                new AdListener() {
                    @Override
                    public void onAdFailedToLoad(int errorCode) {
                        // A native ad failed to load, check if the ad loader has finished loading
                        // and if so, insert the ads into the list.
                        Log.e("MainActivity", "The previous native ad failed to load. Attempting to"
                                + " load another.");
                        if (!adLoader.isLoading()) {
                            insertAdsInMenuItems();
                        }
                    }
                }).build();

        // Load the Native Express ad.
    }
 
Example #27
Source Project: Instagram-Profile-Downloader   Author: beNitinhere   File: DownloadHistoryVideoFragment.java    License: MIT License 5 votes vote down vote up
private void loadNativeAds() {

        AdLoader.Builder builder = new AdLoader.Builder(context, getString(R.string.native_ad_id));
        adLoader = builder.forUnifiedNativeAd(
                new UnifiedNativeAd.OnUnifiedNativeAdLoadedListener() {
                    @Override
                    public void onUnifiedNativeAdLoaded(UnifiedNativeAd unifiedNativeAd) {
                        // A native ad loaded successfully, check if the ad loader has finished loading
                        // and if so, insert the ads into the list.
                        mNativeAds.add(unifiedNativeAd);
                        if (!adLoader.isLoading()) {
                            insertAdsInMenuItems();
                        }
                    }
                }).withAdListener(
                new AdListener() {
                    @Override
                    public void onAdFailedToLoad(int errorCode) {
                        // A native ad failed to load, check if the ad loader has finished loading
                        // and if so, insert the ads into the list.
                        Log.e("MainActivity", "The previous native ad failed to load. Attempting to"
                                + " load another.");
                        if (!adLoader.isLoading()) {
                            insertAdsInMenuItems();
                        }
                    }
                }).build();

        // Load the Native Express ad.
    }
 
Example #28
Source Project: YTPlayer   Author: KaustubhPatange   File: MusicService.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void showAd(Context con) {
    if (AppSettings.playAdCount%AppSettings.adOffset==0 && AppSettings.playAdCount!=0 && AppSettings.showAds && !localPlayBack) {
        Log.e(TAG, "showAd: Showing Ad..." );
        //TODO: Change ad unit ID, Sample ca-app-pub-3940256099942544/1033173712
        try {
            PlayerActivity2.showAd();
        }catch (Exception ex){
            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 #29
Source Project: GDPR-Admob-Android   Author: ayoubfletcher   File: MainActivity.java    License: MIT License 5 votes vote down vote up
private void loadInterstitial() {
    final InterstitialAd interstitialAd = new InterstitialAd(this);
    interstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
    // You have to pass the AdRequest from ConsentSDK.getAdRequest(this) because it handle the right way to load the ad
    interstitialAd.loadAd(ConsentSDK.getAdRequest(this));
    interstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            // Show interstitial
            interstitialAd.show();
            super.onAdLoaded();
        }
    });
}
 
Example #30
Source Project: homeassist   Author: axzae   File: MapActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void setupAdSense() {
    Log.d("YouQi", "Map Adsense: " + ((FirebaseRemoteConfig.getInstance().getBoolean("adsense_map")) ? "Yes" : "No"));
    if (FirebaseRemoteConfig.getInstance().getBoolean("adsense_map")) {
        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId(getString(R.string.banner_ad_unit_id_interstitial));
        mInterstitialAd.loadAd(CommonUtil.getAdRequest());
        mInterstitialAd.setAdListener(new AdListener() {
            public void onAdLoaded() {
                mInterstitialAd.show();
            }
        });
    }
}