Java Code Examples for com.google.android.gms.ads.InterstitialAd#loadAd()

The following examples show how to use com.google.android.gms.ads.InterstitialAd#loadAd() . 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: 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 2
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 3
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 4
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 5
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 6
Source File: NavigationActivity.java    From IdealMedia with Apache License 2.0 5 votes vote down vote up
private void requestInterstitial() {
    if (Settings.PREMIUM || hasPremiumPurchase())
        return;

    if (!Settings.INTERSTITIAL_ENABLED)
        return;

    Date lastInterstitialDate = new Date(PreferenceManager.getDefaultSharedPreferences(this).getLong(getString(R.string.key_interstitial_date), 0));
    if (lastInterstitialDate.getTime() + 1000 * 60 * 60 * 24 * 7 < new Date().getTime()) {
        interstitial = new InterstitialAd(this);
        interstitial.setAdUnitId(getString(R.string.admob_interstitial));
        AdRequest adRequest = new AdRequest.Builder().build();
        interstitial.loadAd(adRequest);
    }
}
 
Example 7
Source File: MainActivity.java    From MockSMS with Apache License 2.0 5 votes vote down vote up
private void startDaWork() {
    if (!adFoe) {
        AdView mAdView = findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);

        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId(All.ID_0_INTER);
        mInterstitialAd.loadAd(new AdRequest.Builder().build());
        mInterstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                Extra.getInstance(getBaseContext()).setCount(0);
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                Crashlytics.log("Ad ErrorCode" + errorCode);
            }

            @Override
            public void onAdOpened() {
                Extra.getInstance(getBaseContext()).setCount(0);
            }

            @Override
            public void onAdLeftApplication() {
                Extra.getInstance(getBaseContext()).setCount(0);
            }

            @Override
            public void onAdClosed() {
                mInterstitialAd.loadAd(new AdRequest.Builder().build());
            }
        });
    }
}
 
Example 8
Source File: MapActivity.java    From homeassist with 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();
            }
        });
    }
}
 
Example 9
Source File: MainActivity.java    From GDPR-Admob-Android with 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 10
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 11
Source File: AdsManager.java    From FruitCatcher with Apache License 2.0 5 votes vote down vote up
public void showInterstitial(Activity activity, String interstitialAdUnitId) {
    final String interstitialAdTimeKey = "InterstitialAdTime";
    final SharedPreferences preferences = PreferenceManager
            .getDefaultSharedPreferences(activity.getBaseContext());
    long adTime = preferences.getLong(interstitialAdTimeKey, 0);
    long now = (new Date()).getTime();
    long dayMs = 24*3600*1000;
    if (now - adTime < dayMs) {
        return;
    }
    interstitial = new InterstitialAd(activity);
    interstitial.setAdUnitId(interstitialAdUnitId);
    // Create ad request.
    AdRequest adRequest = new AdRequest.Builder().build();
    // Begin loading your interstitial.
    interstitial.loadAd(adRequest);
    interstitial.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            try {
                if (interstitial.isLoaded()) {
                    SharedPreferences.Editor edit = preferences.edit();
                    edit.putLong(interstitialAdTimeKey, (new Date()).getTime());
                    edit.commit();
                    interstitial.show();
                }
            }
            catch(Exception ex) {
            }
        }
    });
}
 
Example 12
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 13
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 14
Source File: DetailActivity.java    From Birdays with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_detail);
    ButterKnife.bind(this);

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    boolean adEnabled = preferences.getBoolean(getString(R.string.ad_interstitial_key), true);
    displayedAge = preferences.getString(Constants.DISPLAYED_AGE_KEY, "0");

    /*
    * Interstitial doesn't work on Android API 26+
    * java.lang.IllegalStateException: Only fullscreen activities can request orientation
    */
    mInterstitialAd = new InterstitialAd(this);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O && adEnabled) {
        mInterstitialAd.setAdUnitId(BuildConfig.INTERSTITIAL_AD_ID);
        mInterstitialAd.loadAd(new AdRequest.Builder().build());
    }

    dbHelper = new DbHelper(this);

    Utils.setupDayNightTheme(preferences);

    Intent intent = getIntent();
    timeStamp = intent.getLongExtra(Constants.TIME_STAMP, 0);
    person = dbHelper.query().getPerson(timeStamp);
    date = person.getDate();
    yearUnknown = person.isYearUnknown();
    phoneNumber = person.getPhoneNumber();
    email = person.getEmail();

    toolbar.setTitle(person.getName());
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) actionBar.setDisplayHomeAsUpEnabled(true);

    setupUI();

    loadBornThisDay();

    recyclerView.setFocusable(false);

    rateThisAppInit(this);
}
 
Example 15
Source File: DownloadProfileImageActivity.java    From Instagram-Profile-Downloader with MIT License 4 votes vote down vote up
private void loadFullscreenAd() {
    mInterstitialAd = new InterstitialAd(this);
    mInterstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));
    mInterstitialAd.loadAd(new AdRequest.Builder()
            .build());
}
 
Example 16
Source File: Interstitial.java    From admob-plus with MIT License 4 votes vote down vote up
void load(String adUnitId, AdRequest adRequest) {
    interstitial = new InterstitialAd(plugin.getContext());
    interstitial.setAdUnitId(adUnitId);
    interstitial.setAdListener(new Ad.Listener(this));
    interstitial.loadAd(adRequest);
}
 
Example 17
Source File: MainActivity.java    From MockSMS with Apache License 2.0 4 votes vote down vote up
private void startDaWork() {
    AdView mAdView = new AdView(MainActivity.this);
    mAdView.setAdSize(AdSize.SMART_BANNER);
    mAdView.setAdUnitId(All.ID_1_BAN);

    LinearLayout container = findViewById(R.id.adContainer);
    container.addView(mAdView, container.getChildCount());

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

    mInterstitialAd = new InterstitialAd(this);
    mInterstitialAd.setAdUnitId(All.ID_1_INTER);
    mInterstitialAd.loadAd(new AdRequest.Builder().build());
    mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            Crashlytics.log("Ad ErrorCode" + errorCode);
        }

        @Override
        public void onAdOpened() {
            Extra.getInstance(getBaseContext()).setClickCount(0);
        }

        @Override
        public void onAdLeftApplication() {
            Extra.getInstance(getBaseContext()).setClickCount(0);
        }

        @Override
        public void onAdClosed() {
            mInterstitialAd.loadAd(new AdRequest.Builder().build());
        }
    });

}
 
Example 18
Source File: MainActivity.java    From Instagram-Profile-Downloader with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);
    AudienceNetworkAds.initialize(this);
    dataObjectRepositry = DataObjectRepositry.dataObjectRepositry;
    ButterKnife.bind(this);
    getSafeIntent();
    initUI();
    onClick();
    addToFirebase();


    interstitialAd = new InterstitialAd(this);
    interstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));
    AdRequest adRequest = new AdRequest.Builder().build();
    interstitialAd.loadAd(adRequest);

    allLoginUserList.clear();
    LiveData<List<Logins>> loggedInUsers = DataObjectRepositry.dataObjectRepositry.getAllUsers();
    loggedInUsers.observe(MainActivity.this, new Observer<List<Logins>>() {
        @Override
        public void onChanged(List<Logins> logins) {
            if (logins.size() > 0) {
                allLoginUserList.clear();
                for (Logins logins1 : logins) {

                    DrawerMenuPojo drawerMenuPojo1 = new DrawerMenuPojo();
                    drawerMenuPojo1.setMenuName(logins1.getUserName());
                    drawerMenuPojo1.setImage(R.drawable.ic_account);
                    allLoginUserList.add(drawerMenuPojo1);

                }
            }
        }
    });


    if (!TextUtils.isEmpty(user_id)) {

        showLoading();
        new GetUserInfo(user_id).execute();
    } else {

        changeFragment(new StoriesFragment());
        toolbar.setTitle("Stories");
    }
    toolbar.setTitle("Stories");
}
 
Example 19
Source File: ThemeActivity.java    From AndroidKeyboard with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_theme);

    ImageButton themeButton1 = findViewById(R.id.theme1_imageButton);
    ImageButton themeButton2 = findViewById(R.id.theme2_imageButton);
    ImageButton themeButton3 = findViewById(R.id.theme3_imageButton);
    ImageButton themeButton4 = findViewById(R.id.theme4_imageButton);
    ImageButton themeButton5 = findViewById(R.id.theme5_imageButton);
    ImageButton themeButton6 = findViewById(R.id.theme6_imageButton);
    ImageButton themeButton7 = findViewById(R.id.theme7_imageButton);
    ImageButton themeButton8 = findViewById(R.id.theme8_imageButton);
    ImageButton themeButton9 = findViewById(R.id.theme9_imageButton);
    ImageButton themeButton10 = findViewById(R.id.theme10_imageButton);

    themeButton1.setOnClickListener(this);
    themeButton2.setOnClickListener(this);
    themeButton3.setOnClickListener(this);
    themeButton4.setOnClickListener(this);
    themeButton5.setOnClickListener(this);
    themeButton6.setOnClickListener(this);
    themeButton7.setOnClickListener(this);
    themeButton8.setOnClickListener(this);
    themeButton9.setOnClickListener(this);
    themeButton10.setOnClickListener(this);

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    if(getActionBar() != null){
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }

    AdView adView = this.findViewById(R.id.adView);
    adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .addTestDevice("D17FE6D8441E3F2375E3709A2EED851B")
            .build();
    adView.loadAd(adRequest);

    // Display the full screen Ad after third visit.
    counter = sharedPreferences.getInt(AD_COUNT, 0);
    editor = sharedPreferences.edit();

    if(2 == counter) {
        interstitialAd = new InterstitialAd(this);
        interstitialAd.setAdUnitId(getString(R.string.interstitial_unitID));
        interstitialAd.loadAd(adRequest);
    } else {
        editor.putInt(AD_COUNT, sharedPreferences.getInt(AD_COUNT, 0) + 1).apply();
    }
}
 
Example 20
Source File: DownloadHistoryActivity.java    From Instagram-Profile-Downloader with MIT License 4 votes vote down vote up
private void loadFullscreenAd() {
    mInterstitialAd = new InterstitialAd(this);
    mInterstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));
    mInterstitialAd.loadAd(new AdRequest.Builder()
            .build());
}