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

The following examples show how to use com.google.android.gms.ads.InterstitialAd#setAdUnitId() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
Source File: MainActivity.java    From GooglePlayServiceLocationSupport with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mOldLocation = (TextView) findViewById(R.id.oldlocation);
    mNewLocation = (TextView) findViewById(R.id.newlocation);
    AdView mAdView = (AdView) findViewById(R.id.adView);

    mInterstitialAd = new InterstitialAd(this);
    mInterstitialAd.setAdUnitId(getResources().getString(R.string.interstitial_ad));
    mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            startActivity(new Intent(MainActivity.this, FragmentLocationActivity.class));
        }
    });
    AdRequest adRequest = new AdRequest.Builder().build();
    mInterstitialAd.loadAd(adRequest);

    adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
    findViewById(R.id.btn_fragment).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mInterstitialAd != null && mInterstitialAd.isLoaded())
                mInterstitialAd.show();
            else startActivity(new Intent(MainActivity.this, FragmentLocationActivity.class));
        }
    });
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
}
 
Example 11
Source File: GoogleAdActivity.java    From FastLib with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_google_ad);

    // 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() {
            ToastUtil.show("onAdLoaded()");
        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            ToastUtil.show("onAdFailedToLoad() with error code: " + errorCode);
        }

        @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 12
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 13
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 14
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 15
Source File: ViewStoryActivity.java    From Instagram-Profile-Downloader with MIT License 5 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_view_story);
    adContainer = findViewById(R.id.adContainer);
    showBannerAd();
    viewPager = findViewById(R.id.story_view_pager);

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


    modelList = new ArrayList<>();
    urls = new ArrayList<>();
    if (getIntent() != null) {
        isDownloadPostImage = getIntent().getBooleanExtra("isDownloadPostImage", false);
        isAlreadyDownloaded = getIntent().getBooleanExtra("isAlreadyDownloaded", false);
        isFromDownloadScreen = getIntent().getBooleanExtra("isFromDownloadScreen", false);

    }

    loadStories();
    adapter = new StoryViewPagerAdapter(getSupportFragmentManager(), modelList, isFromNet, urls, isDownloadPostImage, isAlreadyDownloaded, isFromDownloadScreen);
    viewPager.setAdapter(adapter);
    viewPager.addOnPageChangeListener(this);
    viewPager.setOffscreenPageLimit(2);
    viewPager.setCurrentItem(position);


}
 
Example 16
Source File: AdMob.java    From capacitor-admob with MIT License 4 votes vote down vote up
@PluginMethod()
public void prepareInterstitial(final PluginCall call) {
    this.call = call;
    /* dedicated test ad unit ID for Android interstitials:
        ca-app-pub-3940256099942544/1033173712
    */
    String adId = call.getString("adId", "ca-app-pub-3940256099942544/1033173712");


    try {

        mInterstitialAd = new InterstitialAd(getContext());
        mInterstitialAd.setAdUnitId(adId);


        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                mInterstitialAd.loadAd(new AdRequest.Builder().build());

                mInterstitialAd.setAdListener(new AdListener() {
                    @Override
                    public void onAdLoaded() {
                        // Code to be executed when an ad finishes loading.
                        notifyListeners("onAdLoaded", new JSObject().put("value", true));
                        call.success(new JSObject().put("value", true));
                        super.onAdLoaded();

                    }

                    @Override
                    public void onAdFailedToLoad(int errorCode) {
                        // Code to be executed when an ad request fails.
                        notifyListeners("onAdFailedToLoad", new JSObject().put("errorCode", errorCode));
                        super.onAdFailedToLoad(errorCode);
                    }

                    @Override
                    public void onAdOpened() {
                        // Code to be executed when the ad is displayed.
                        notifyListeners("onAdOpened", new JSObject().put("value", true));
                        super.onAdOpened();
                    }

                    @Override
                    public void onAdLeftApplication() {
                        // Code to be executed when the user has left the app.
                        notifyListeners("onAdLeftApplication", new JSObject().put("value", true));
                        super.onAdLeftApplication();
                    }

                    @Override
                    public void onAdClosed() {
                        // Code to be executed when when the interstitial ad is closed.
                        notifyListeners("onAdClosed", new JSObject().put("value", true));
                        super.onAdClosed();
                    }
                });

            }
        });

    }catch (Exception ex) {
        call.error(ex.getLocalizedMessage(), ex);
    }
}
 
Example 17
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 18
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 19
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 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());
}