code
stringlengths
23
201k
docstring
stringlengths
17
96.2k
func_name
stringlengths
0
235
language
stringclasses
1 value
repo
stringlengths
8
72
path
stringlengths
11
317
url
stringlengths
57
377
license
stringclasses
7 values
public boolean isPrivacyOptionsRequired() { return consentInformation.getPrivacyOptionsRequirementStatus() == PrivacyOptionsRequirementStatus.REQUIRED; }
Helper variable to determine if the privacy options form is required.
isPrivacyOptionsRequired
java
googleads/googleads-mobile-android-examples
java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/GoogleMobileAdsConsentManager.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/GoogleMobileAdsConsentManager.java
Apache-2.0
public void gatherConsent( Activity activity, OnConsentGatheringCompleteListener onConsentGatheringCompleteListener) { // For testing purposes, you can force a DebugGeography of EEA or NOT_EEA. ConsentDebugSettings debugSettings = new ConsentDebugSettings.Builder(activity) // .setDebug...
Helper method to call the UMP SDK methods to request consent information and load/present a consent form if necessary.
gatherConsent
java
googleads/googleads-mobile-android-examples
java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/GoogleMobileAdsConsentManager.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/GoogleMobileAdsConsentManager.java
Apache-2.0
public void showPrivacyOptionsForm( Activity activity, OnConsentFormDismissedListener onConsentFormDismissedListener) { UserMessagingPlatform.showPrivacyOptionsForm(activity, onConsentFormDismissedListener); }
Helper method to call the UMP SDK method to present the privacy options form.
showPrivacyOptionsForm
java
googleads/googleads-mobile-android-examples
java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/GoogleMobileAdsConsentManager.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/GoogleMobileAdsConsentManager.java
Apache-2.0
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my); // Log the Mobile Ads SDK version. Log.d(TAG, "Google Mobile Ads SDK Version: " + MobileAds.getVersion()); googleMobileAdsConsentManager = GoogleMobile...
Main Activity. Inflates main activity xml.
onCreate
java
googleads/googleads-mobile-android-examples
java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
Apache-2.0
@Override public void onClick(View view) { showInterstitial(); }
Main Activity. Inflates main activity xml.
onClick
java
googleads/googleads-mobile-android-examples
java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
Apache-2.0
public void loadAd() { // Request a new ad if one isn't already loaded. if (adIsLoading || interstitialAd != null) { return; } adIsLoading = true; // [START load_ad] InterstitialAd.load( this, AD_UNIT_ID, new AdRequest.Builder().build(), new InterstitialAdLo...
Main Activity. Inflates main activity xml.
loadAd
java
googleads/googleads-mobile-android-examples
java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
Apache-2.0
@Override public void onAdLoaded(@NonNull InterstitialAd interstitialAd) { Log.d(TAG, "Ad was loaded."); MyActivity.this.interstitialAd = interstitialAd; // [START_EXCLUDE silent] adIsLoading = false; Toast.makeText(MyActivity.this, "onAdLoaded()", T...
Main Activity. Inflates main activity xml.
onAdLoaded
java
googleads/googleads-mobile-android-examples
java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
Apache-2.0
@Override public void onAdDismissedFullScreenContent() { // Called when fullscreen content is dismissed. Log.d(TAG, "The ad was dismissed."); // Make sure to set your reference to null so you don't // show it a second time...
Main Activity. Inflates main activity xml.
onAdDismissedFullScreenContent
java
googleads/googleads-mobile-android-examples
java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
Apache-2.0
@Override public void onAdFailedToShowFullScreenContent(AdError adError) { // Called when fullscreen content failed to show. Log.d(TAG, "The ad failed to show."); // Make sure to set your reference to null so you don't // ...
Main Activity. Inflates main activity xml.
onAdFailedToShowFullScreenContent
java
googleads/googleads-mobile-android-examples
java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
Apache-2.0
@Override public void onAdShowedFullScreenContent() { // Called when fullscreen content is shown. Log.d(TAG, "The ad was shown."); }
Main Activity. Inflates main activity xml.
onAdShowedFullScreenContent
java
googleads/googleads-mobile-android-examples
java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
Apache-2.0
@Override public void onAdImpression() { // Called when an impression is recorded for an ad. Log.d(TAG, "The ad recorded an impression."); }
Main Activity. Inflates main activity xml.
onAdImpression
java
googleads/googleads-mobile-android-examples
java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
Apache-2.0
@Override public void onAdClicked() { // Called when ad is clicked. Log.d(TAG, "The ad was clicked."); }
Main Activity. Inflates main activity xml.
onAdClicked
java
googleads/googleads-mobile-android-examples
java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
Apache-2.0
@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) { Log.d(TAG, loadAdError.getMessage()); interstitialAd = null; // [START_EXCLUDE silent] adIsLoading = false; String error = String.format( j...
Main Activity. Inflates main activity xml.
onAdFailedToLoad
java
googleads/googleads-mobile-android-examples
java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
Apache-2.0
private void createTimer(final long milliseconds) { // Create the game timer, which counts down to the end of the level // and shows the "retry" button. if (countDownTimer != null) { countDownTimer.cancel(); } final TextView textView = findViewById(R.id.timer); countDownTimer = n...
Main Activity. Inflates main activity xml.
createTimer
java
googleads/googleads-mobile-android-examples
java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
Apache-2.0
@Override public void onTick(long millisUnitFinished) { timerMilliseconds = millisUnitFinished; textView.setText("seconds remaining: " + ((millisUnitFinished / 1000) + 1)); }
Main Activity. Inflates main activity xml.
onTick
java
googleads/googleads-mobile-android-examples
java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
Apache-2.0
@Override public void onFinish() { gameOver = true; textView.setText("done!"); retryButton.setVisibility(View.VISIBLE); }
Main Activity. Inflates main activity xml.
onFinish
java
googleads/googleads-mobile-android-examples
java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
Apache-2.0
@Override public void onResume() { // Start or resume the game. super.onResume(); resumeGame(); }
Main Activity. Inflates main activity xml.
onResume
java
googleads/googleads-mobile-android-examples
java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
Apache-2.0
@Override public void onPause() { super.onPause(); pauseGame(); }
Main Activity. Inflates main activity xml.
onPause
java
googleads/googleads-mobile-android-examples
java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
Apache-2.0
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.action_menu, menu); return true; }
Main Activity. Inflates main activity xml.
onCreateOptionsMenu
java
googleads/googleads-mobile-android-examples
java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
Apache-2.0
@Override public boolean onOptionsItemSelected(MenuItem item) { View menuItemView = findViewById(item.getItemId()); PopupMenu popup = new PopupMenu(this, menuItemView); popup.getMenuInflater().inflate(R.menu.popup_menu, popup.getMenu()); popup.show(); popup .getMenu() .findItem(R.i...
Main Activity. Inflates main activity xml.
onOptionsItemSelected
java
googleads/googleads-mobile-android-examples
java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
Apache-2.0
private void showInterstitial() { // Show the ad if it's ready. Otherwise restart the game. // [START show_ad] if (interstitialAd != null) { interstitialAd.show(this); } else { Log.d(TAG, "The interstitial ad is still loading."); // [START_EXCLUDE silent] startGame(); if (g...
Main Activity. Inflates main activity xml.
showInterstitial
java
googleads/googleads-mobile-android-examples
java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
Apache-2.0
private void startGame() { // Hide the button, and kick off the timer. retryButton.setVisibility(View.INVISIBLE); createTimer(GAME_LENGTH_MILLISECONDS); gamePaused = false; gameOver = false; }
Main Activity. Inflates main activity xml.
startGame
java
googleads/googleads-mobile-android-examples
java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
Apache-2.0
private void resumeGame() { if (gameOver || !gamePaused) { return; } // Create a new timer for the correct length. gamePaused = false; createTimer(timerMilliseconds); }
Main Activity. Inflates main activity xml.
resumeGame
java
googleads/googleads-mobile-android-examples
java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
Apache-2.0
private void pauseGame() { if (gameOver || gamePaused) { return; } countDownTimer.cancel(); gamePaused = true; }
Main Activity. Inflates main activity xml.
pauseGame
java
googleads/googleads-mobile-android-examples
java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
Apache-2.0
private void initializeMobileAdsSdk() { if (isMobileAdsInitializeCalled.getAndSet(true)) { return; } // Set your test devices. MobileAds.setRequestConfiguration( new RequestConfiguration.Builder() .setTestDeviceIds(Arrays.asList(TEST_DEVICE_HASHED_ID)) .build()); ...
Main Activity. Inflates main activity xml.
initializeMobileAdsSdk
java
googleads/googleads-mobile-android-examples
java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java
Apache-2.0
public boolean canRequestAds() { return consentInformation.canRequestAds(); }
Helper variable to determine if the app can request ads.
canRequestAds
java
googleads/googleads-mobile-android-examples
java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/GoogleMobileAdsConsentManager.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/GoogleMobileAdsConsentManager.java
Apache-2.0
public boolean isPrivacyOptionsRequired() { return consentInformation.getPrivacyOptionsRequirementStatus() == PrivacyOptionsRequirementStatus.REQUIRED; }
Helper variable to determine if the privacy options form is required.
isPrivacyOptionsRequired
java
googleads/googleads-mobile-android-examples
java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/GoogleMobileAdsConsentManager.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/GoogleMobileAdsConsentManager.java
Apache-2.0
public void gatherConsent( Activity activity, OnConsentGatheringCompleteListener onConsentGatheringCompleteListener) { // For testing purposes, you can force a DebugGeography of EEA or NOT_EEA. ConsentDebugSettings debugSettings = new ConsentDebugSettings.Builder(activity) // .setDebug...
Helper method to call the UMP SDK methods to request consent information and load/present a consent form if necessary.
gatherConsent
java
googleads/googleads-mobile-android-examples
java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/GoogleMobileAdsConsentManager.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/GoogleMobileAdsConsentManager.java
Apache-2.0
public void showPrivacyOptionsForm( Activity activity, OnConsentFormDismissedListener onConsentFormDismissedListener) { UserMessagingPlatform.showPrivacyOptionsForm(activity, onConsentFormDismissedListener); }
Helper method to call the UMP SDK method to present the privacy options form.
showPrivacyOptionsForm
java
googleads/googleads-mobile-android-examples
java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/GoogleMobileAdsConsentManager.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/GoogleMobileAdsConsentManager.java
Apache-2.0
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); refresh = findViewById(R.id.btn_refresh); startVideoAdsMuted = findViewById(R.id.cb_start_muted); videoStatus = findViewById(R.id.tv_video_status); // Lo...
A simple activity class that displays native ad formats.
onCreate
java
googleads/googleads-mobile-android-examples
java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/MainActivity.java
Apache-2.0
@Override public void onClick(View unusedView) { if (googleMobileAdsConsentManager.canRequestAds()) { refreshAd(); } }
A simple activity class that displays native ad formats.
onClick
java
googleads/googleads-mobile-android-examples
java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/MainActivity.java
Apache-2.0
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.action_menu, menu); return true; }
A simple activity class that displays native ad formats.
onCreateOptionsMenu
java
googleads/googleads-mobile-android-examples
java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/MainActivity.java
Apache-2.0
@Override public boolean onOptionsItemSelected(MenuItem item) { View menuItemView = findViewById(item.getItemId()); PopupMenu popup = new PopupMenu(this, menuItemView); popup.getMenuInflater().inflate(R.menu.popup_menu, popup.getMenu()); popup .getMenu() .findItem(R.id.privacy_settings...
A simple activity class that displays native ad formats.
onOptionsItemSelected
java
googleads/googleads-mobile-android-examples
java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/MainActivity.java
Apache-2.0
private void populateNativeAdView(NativeAd nativeAd, NativeAdView adView) { // Set the media view. adView.setMediaView((MediaView) adView.findViewById(R.id.ad_media)); // Set other ad assets. adView.setHeadlineView(adView.findViewById(R.id.ad_headline)); adView.setBodyView(adView.findViewById(R.id....
Populates a {@link NativeAdView} object with data from a given {@link NativeAd}. @param nativeAd the object containing the ad's assets @param adView the view to be populated
populateNativeAdView
java
googleads/googleads-mobile-android-examples
java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/MainActivity.java
Apache-2.0
@Override public void onVideoEnd() { // Publishers should allow native ads to complete video playback before // refreshing or replacing them with another ad in the same UI location. refresh.setEnabled(true); videoStatus.setText("Video status: Video pla...
Populates a {@link NativeAdView} object with data from a given {@link NativeAd}. @param nativeAd the object containing the ad's assets @param adView the view to be populated
onVideoEnd
java
googleads/googleads-mobile-android-examples
java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/MainActivity.java
Apache-2.0
private void refreshAd() { refresh.setEnabled(false); AdLoader.Builder builder = new AdLoader.Builder(this, ADMOB_AD_UNIT_ID); builder.forNativeAd( new NativeAd.OnNativeAdLoadedListener() { // OnLoadedListener implementation. @Override public void onNativeAdLoaded(Nat...
Creates a request for a new native ad based on the boolean parameters and calls the corresponding "populate" method when one is successfully returned.
refreshAd
java
googleads/googleads-mobile-android-examples
java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/MainActivity.java
Apache-2.0
@Override public void onNativeAdLoaded(NativeAd nativeAd) { // If this callback occurs after the activity is destroyed, you must call // destroy and return or you may get a memory leak. boolean isDestroyed = false; refresh.setEnabled(true); if (Build...
Creates a request for a new native ad based on the boolean parameters and calls the corresponding "populate" method when one is successfully returned.
onNativeAdLoaded
java
googleads/googleads-mobile-android-examples
java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/MainActivity.java
Apache-2.0
@Override public void onAdFailedToLoad(LoadAdError loadAdError) { refresh.setEnabled(true); String error = String.format( Locale.getDefault(), "domain: %s, code: %d, message: %s", ...
Creates a request for a new native ad based on the boolean parameters and calls the corresponding "populate" method when one is successfully returned.
onAdFailedToLoad
java
googleads/googleads-mobile-android-examples
java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/MainActivity.java
Apache-2.0
private void initializeMobileAdsSdk() { if (isMobileAdsInitializeCalled.getAndSet(true)) { return; } // Set your test devices. MobileAds.setRequestConfiguration( new RequestConfiguration.Builder() .setTestDeviceIds(Arrays.asList(TEST_DEVICE_HASHED_ID)) .build()); ...
Creates a request for a new native ad based on the boolean parameters and calls the corresponding "populate" method when one is successfully returned.
initializeMobileAdsSdk
java
googleads/googleads-mobile-android-examples
java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/MainActivity.java
Apache-2.0
@Override protected void onDestroy() { if (nativeAd != null) { nativeAd.destroy(); } super.onDestroy(); }
Creates a request for a new native ad based on the boolean parameters and calls the corresponding "populate" method when one is successfully returned.
onDestroy
java
googleads/googleads-mobile-android-examples
java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/NativeAdvancedExample/app/src/main/java/com/google/example/gms/nativeadvancedexample/MainActivity.java
Apache-2.0
public static AdDialogFragment newInstance(int rewardAmount, String rewardType) { AdDialogFragment fragment = new AdDialogFragment(); Bundle args = new Bundle(); args.putInt(REWARD_AMOUNT, rewardAmount); args.putString(REWARD_TYPE, rewardType); fragment.setArguments(args); return fragment; }
Creates an instance of the AdDialogFragment and sets reward information for its title. @param rewardAmount Number of coins rewarded by watching an ad. @param rewardType The unit of the reward amount. For example: coins, tokens, life, etc.
newInstance
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/AdDialogFragment.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/AdDialogFragment.java
Apache-2.0
public void setAdDialogInteractionListener(AdDialogInteractionListener listener) { this.listener = listener; }
Registers the callbacks to be invoked when the user interacts with this dialog. If there is no user interactions, the dialog is dismissed and the user will see a video interstitial ad. @param listener The callbacks that will run when the user interacts with this dialog.
setAdDialogInteractionListener
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/AdDialogFragment.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/AdDialogFragment.java
Apache-2.0
@NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Inflate and set the layout for the dialog. // Pass null as the parent view because its going in the dialog layout. View view = requireActivi...
Registers the callbacks to be invoked when the user interacts with this dialog. If there is no user interactions, the dialog is dismissed and the user will see a video interstitial ad. @param listener The callbacks that will run when the user interacts with this dialog.
onCreateDialog
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/AdDialogFragment.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/AdDialogFragment.java
Apache-2.0
@Override public void onClick(DialogInterface dialog, int id) { getDialog().cancel(); }
Registers the callbacks to be invoked when the user interacts with this dialog. If there is no user interactions, the dialog is dismissed and the user will see a video interstitial ad. @param listener The callbacks that will run when the user interacts with this dialog.
onClick
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/AdDialogFragment.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/AdDialogFragment.java
Apache-2.0
private void createTimer(long time, View dialogView) { final TextView textView = dialogView.findViewById(R.id.timer); countDownTimer = new CountDownTimer(time, 50) { @Override public void onTick(long millisUnitFinished) { timeRemaining = MILLISECONDS.toSeconds(millisUnitF...
Creates the a timer to count down until the rewarded interstitial ad. @param time Number of milliseconds to count down. @param dialogView The view of this dialog for updating the remaining seconds count.
createTimer
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/AdDialogFragment.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/AdDialogFragment.java
Apache-2.0
@Override public void onTick(long millisUnitFinished) { timeRemaining = MILLISECONDS.toSeconds(millisUnitFinished) + 1; textView.setText( String.format(getString(R.string.video_starting_in_text), timeRemaining)); }
Creates the a timer to count down until the rewarded interstitial ad. @param time Number of milliseconds to count down. @param dialogView The view of this dialog for updating the remaining seconds count.
onTick
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/AdDialogFragment.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/AdDialogFragment.java
Apache-2.0
@Override public void onFinish() { getDialog().dismiss(); if (listener != null) { Log.d(TAG, "onFinish: Calling onShowAd()."); listener.onShowAd(); } }
Called when the count down finishes and the user hasn't cancelled the dialog.
onFinish
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/AdDialogFragment.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/AdDialogFragment.java
Apache-2.0
@Override public void onCancel(@NonNull DialogInterface dialog) { super.onCancel(dialog); if (listener != null) { Log.d(TAG, "onCancel: Calling onCancelAd()."); listener.onCancelAd(); } }
Called when the user clicks the "No, Thanks" button or press the back button.
onCancel
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/AdDialogFragment.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/AdDialogFragment.java
Apache-2.0
@Override public void onDestroy() { super.onDestroy(); Log.d(TAG, "onDestroy: Cancelling the timer."); countDownTimer.cancel(); countDownTimer = null; }
Called when the fragment is destroyed.
onDestroy
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/AdDialogFragment.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/AdDialogFragment.java
Apache-2.0
public boolean canRequestAds() { return consentInformation.canRequestAds(); }
Helper variable to determine if the app can request ads.
canRequestAds
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/GoogleMobileAdsConsentManager.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/GoogleMobileAdsConsentManager.java
Apache-2.0
public boolean isPrivacyOptionsRequired() { return consentInformation.getPrivacyOptionsRequirementStatus() == PrivacyOptionsRequirementStatus.REQUIRED; }
Helper variable to determine if the privacy options form is required.
isPrivacyOptionsRequired
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/GoogleMobileAdsConsentManager.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/GoogleMobileAdsConsentManager.java
Apache-2.0
public void gatherConsent( Activity activity, OnConsentGatheringCompleteListener onConsentGatheringCompleteListener) { // For testing purposes, you can force a DebugGeography of EEA or NOT_EEA. ConsentDebugSettings debugSettings = new ConsentDebugSettings.Builder(activity) // .setDebug...
Helper method to call the UMP SDK methods to request consent information and load/present a consent form if necessary.
gatherConsent
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/GoogleMobileAdsConsentManager.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/GoogleMobileAdsConsentManager.java
Apache-2.0
public void showPrivacyOptionsForm( Activity activity, OnConsentFormDismissedListener onConsentFormDismissedListener) { UserMessagingPlatform.showPrivacyOptionsForm(activity, onConsentFormDismissedListener); }
Helper method to call the UMP SDK method to present the privacy options form.
showPrivacyOptionsForm
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/GoogleMobileAdsConsentManager.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/GoogleMobileAdsConsentManager.java
Apache-2.0
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Log the Mobile Ads SDK version. Log.d(TAG, "Google Mobile Ads SDK Version: " + MobileAds.getVersion()); googleMobileAdsConsentManager = GoogleMobi...
Main Activity. Inflates main activity xml.
onCreate
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
Apache-2.0
@Override public void onClick(View view) { startGame(); if (rewardedInterstitialAd != null && !isLoadingAds && googleMobileAdsConsentManager.canRequestAds()) { loadRewardedInterstitialAd(); } }
Main Activity. Inflates main activity xml.
onClick
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
Apache-2.0
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.action_menu, menu); return true; }
Main Activity. Inflates main activity xml.
onCreateOptionsMenu
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
Apache-2.0
@Override public boolean onOptionsItemSelected(MenuItem item) { View menuItemView = findViewById(item.getItemId()); PopupMenu popup = new PopupMenu(this, menuItemView); popup.getMenuInflater().inflate(R.menu.popup_menu, popup.getMenu()); popup .getMenu() .findItem(R.id.privacy_settings...
Main Activity. Inflates main activity xml.
onOptionsItemSelected
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
Apache-2.0
@Override public void onPause() { super.onPause(); pauseGame(); }
Main Activity. Inflates main activity xml.
onPause
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
Apache-2.0
@Override public void onResume() { super.onResume(); resumeGame(); }
Main Activity. Inflates main activity xml.
onResume
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
Apache-2.0
private void pauseGame() { if (gameOver || gamePaused) { return; } countDownTimer.cancel(); gamePaused = true; }
Main Activity. Inflates main activity xml.
pauseGame
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
Apache-2.0
private void resumeGame() { if (gameOver || !gamePaused) { return; } createTimer(timeRemaining); gamePaused = false; }
Main Activity. Inflates main activity xml.
resumeGame
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
Apache-2.0
private void loadRewardedInterstitialAd() { if (rewardedInterstitialAd == null) { isLoadingAds = true; AdRequest adRequest = new AdRequest.Builder().build(); // Use the test ad unit ID to load an ad. RewardedInterstitialAd.load( MainActivity.this, AD_UNIT_ID, a...
Main Activity. Inflates main activity xml.
loadRewardedInterstitialAd
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
Apache-2.0
@Override public void onAdLoaded(RewardedInterstitialAd ad) { Log.d(TAG, "onAdLoaded"); rewardedInterstitialAd = ad; isLoadingAds = false; Toast.makeText(MainActivity.this, "onAdLoaded", Toast.LENGTH_SHORT).show(); }
Main Activity. Inflates main activity xml.
onAdLoaded
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
Apache-2.0
@Override public void onAdFailedToLoad(LoadAdError loadAdError) { Log.d(TAG, "onAdFailedToLoad: " + loadAdError.getMessage()); // Handle the error. rewardedInterstitialAd = null; isLoadingAds = false; Toast.makeText(MainActivity.this, "o...
Main Activity. Inflates main activity xml.
onAdFailedToLoad
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
Apache-2.0
private void addCoins(int coins) { coinCount += coins; coinCountText.setText("Coins: " + coinCount); }
Main Activity. Inflates main activity xml.
addCoins
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
Apache-2.0
private void startGame() { // Hide the retry button, load the ad, and start the timer. retryButton.setVisibility(View.INVISIBLE); createTimer(COUNTER_TIME); gamePaused = false; gameOver = false; }
Main Activity. Inflates main activity xml.
startGame
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
Apache-2.0
private void createTimer(long time) { final TextView textView = findViewById(R.id.timer); if (countDownTimer != null) { countDownTimer.cancel(); } countDownTimer = new CountDownTimer(time * 1000, 50) { @Override public void onTick(long millisUnitFinished) { ...
Main Activity. Inflates main activity xml.
createTimer
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
Apache-2.0
@Override public void onTick(long millisUnitFinished) { timeRemaining = ((millisUnitFinished / 1000) + 1); textView.setText("seconds remaining: " + timeRemaining); }
Main Activity. Inflates main activity xml.
onTick
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
Apache-2.0
@Override public void onFinish() { textView.setText("You Lose!"); addCoins(GAME_OVER_REWARD); retryButton.setVisibility(View.VISIBLE); gameOver = true; if (rewardedInterstitialAd == null) { Log.d(TAG, "The rewarded interstitial ad is n...
Main Activity. Inflates main activity xml.
onFinish
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
Apache-2.0
private void introduceVideoAd(int rewardAmount, String rewardType) { AdDialogFragment dialog = AdDialogFragment.newInstance(rewardAmount, rewardType); dialog.setAdDialogInteractionListener( new AdDialogInteractionListener() { @Override public void onShowAd() { Log.d(TAG, ...
Main Activity. Inflates main activity xml.
introduceVideoAd
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
Apache-2.0
@Override public void onShowAd() { Log.d(TAG, "The rewarded interstitial ad is starting."); showRewardedVideo(); }
Main Activity. Inflates main activity xml.
onShowAd
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
Apache-2.0
@Override public void onCancelAd() { Log.d(TAG, "The rewarded interstitial ad was skipped before it starts."); }
Main Activity. Inflates main activity xml.
onCancelAd
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
Apache-2.0
private void showRewardedVideo() { if (rewardedInterstitialAd == null) { Log.d(TAG, "The rewarded interstitial ad wasn't ready yet."); return; } rewardedInterstitialAd.setFullScreenContentCallback( new FullScreenContentCallback() { /** Called when ad showed the full screen co...
Main Activity. Inflates main activity xml.
showRewardedVideo
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
Apache-2.0
@Override public void onAdShowedFullScreenContent() { Log.d(TAG, "onAdShowedFullScreenContent"); Toast.makeText(MainActivity.this, "onAdShowedFullScreenContent", Toast.LENGTH_SHORT) .show(); }
Called when ad showed the full screen content.
onAdShowedFullScreenContent
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
Apache-2.0
@Override public void onAdFailedToShowFullScreenContent(AdError adError) { Log.d(TAG, "onAdFailedToShowFullScreenContent: " + adError.getMessage()); // Don't forget to set the ad reference to null so you // don't show the ad a second time. rewardedInterstitialA...
Called when the ad failed to show full screen content.
onAdFailedToShowFullScreenContent
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
Apache-2.0
@Override public void onAdDismissedFullScreenContent() { // Don't forget to set the ad reference to null so you // don't show the ad a second time. rewardedInterstitialAd = null; Log.d(TAG, "onAdDismissedFullScreenContent"); Toast.makeText(MainActivi...
Called when full screen content is dismissed.
onAdDismissedFullScreenContent
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
Apache-2.0
@Override public void onUserEarnedReward(@NonNull RewardItem rewardItem) { // Handle the reward. Log.d(TAG, "The user earned the reward."); addCoins(rewardItem.getAmount()); }
Called when full screen content is dismissed.
onUserEarnedReward
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
Apache-2.0
private void initializeMobileAdsSdk() { if (isMobileAdsInitializeCalled.getAndSet(true)) { return; } // Set your test devices. MobileAds.setRequestConfiguration( new RequestConfiguration.Builder() .setTestDeviceIds(Arrays.asList(TEST_DEVICE_HASHED_ID)) .build()); ...
Called when full screen content is dismissed.
initializeMobileAdsSdk
java
googleads/googleads-mobile-android-examples
java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedInterstitialExample/app/src/main/java/com/google/ads/rewardedinterstitialexample/MainActivity.java
Apache-2.0
public boolean canRequestAds() { return consentInformation.canRequestAds(); }
Helper variable to determine if the app can request ads.
canRequestAds
java
googleads/googleads-mobile-android-examples
java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/GoogleMobileAdsConsentManager.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/GoogleMobileAdsConsentManager.java
Apache-2.0
public boolean isPrivacyOptionsRequired() { return consentInformation.getPrivacyOptionsRequirementStatus() == PrivacyOptionsRequirementStatus.REQUIRED; }
Helper variable to determine if the privacy options form is required.
isPrivacyOptionsRequired
java
googleads/googleads-mobile-android-examples
java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/GoogleMobileAdsConsentManager.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/GoogleMobileAdsConsentManager.java
Apache-2.0
public void gatherConsent( Activity activity, OnConsentGatheringCompleteListener onConsentGatheringCompleteListener) { // For testing purposes, you can force a DebugGeography of EEA or NOT_EEA. ConsentDebugSettings debugSettings = new ConsentDebugSettings.Builder(activity) // .setDebug...
Helper method to call the UMP SDK methods to request consent information and load/present a consent form if necessary.
gatherConsent
java
googleads/googleads-mobile-android-examples
java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/GoogleMobileAdsConsentManager.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/GoogleMobileAdsConsentManager.java
Apache-2.0
public void showPrivacyOptionsForm( Activity activity, OnConsentFormDismissedListener onConsentFormDismissedListener) { UserMessagingPlatform.showPrivacyOptionsForm(activity, onConsentFormDismissedListener); }
Helper method to call the UMP SDK method to present the privacy options form.
showPrivacyOptionsForm
java
googleads/googleads-mobile-android-examples
java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/GoogleMobileAdsConsentManager.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/GoogleMobileAdsConsentManager.java
Apache-2.0
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Log the Mobile Ads SDK version. Log.d(TAG, "Google Mobile Ads SDK Version: " + MobileAds.getVersion()); googleMobileAdsConsentManager = GoogleMobi...
Main Activity. Inflates main activity xml.
onCreate
java
googleads/googleads-mobile-android-examples
java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
Apache-2.0
@Override public void onClick(View view) { startGame(); if (!isLoading && googleMobileAdsConsentManager.canRequestAds()) { loadRewardedAd(); } }
Main Activity. Inflates main activity xml.
onClick
java
googleads/googleads-mobile-android-examples
java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
Apache-2.0
@Override public void onClick(View view) { showRewardedVideo(); }
Main Activity. Inflates main activity xml.
onClick
java
googleads/googleads-mobile-android-examples
java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
Apache-2.0
@Override public void onPause() { super.onPause(); pauseGame(); }
Main Activity. Inflates main activity xml.
onPause
java
googleads/googleads-mobile-android-examples
java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
Apache-2.0
@Override public void onResume() { super.onResume(); resumeGame(); }
Main Activity. Inflates main activity xml.
onResume
java
googleads/googleads-mobile-android-examples
java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
Apache-2.0
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.action_menu, menu); return true; }
Main Activity. Inflates main activity xml.
onCreateOptionsMenu
java
googleads/googleads-mobile-android-examples
java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
Apache-2.0
@Override public boolean onOptionsItemSelected(MenuItem item) { View menuItemView = findViewById(item.getItemId()); PopupMenu popup = new PopupMenu(this, menuItemView); popup.getMenuInflater().inflate(R.menu.popup_menu, popup.getMenu()); popup .getMenu() .findItem(R.id.privacy_settings...
Main Activity. Inflates main activity xml.
onOptionsItemSelected
java
googleads/googleads-mobile-android-examples
java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
Apache-2.0
private void pauseGame() { if (gameOver || gamePaused) { return; } countDownTimer.cancel(); gamePaused = true; }
Main Activity. Inflates main activity xml.
pauseGame
java
googleads/googleads-mobile-android-examples
java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
Apache-2.0
private void resumeGame() { if (gameOver || !gamePaused) { return; } createTimer(timeRemaining); gamePaused = false; }
Main Activity. Inflates main activity xml.
resumeGame
java
googleads/googleads-mobile-android-examples
java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
Apache-2.0
private void loadRewardedAd() { if (rewardedAd == null) { isLoading = true; AdRequest adRequest = new AdRequest.Builder().build(); RewardedAd.load( this, AD_UNIT_ID, adRequest, new RewardedAdLoadCallback() { @Override public void onAd...
Main Activity. Inflates main activity xml.
loadRewardedAd
java
googleads/googleads-mobile-android-examples
java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
Apache-2.0
@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) { // Handle the error. Log.d(TAG, loadAdError.getMessage()); rewardedAd = null; MainActivity.this.isLoading = false; Toast.makeText(MainActivity.this, "onAdFailedToL...
Main Activity. Inflates main activity xml.
onAdFailedToLoad
java
googleads/googleads-mobile-android-examples
java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
Apache-2.0
@Override public void onAdLoaded(@NonNull RewardedAd rewardedAd) { MainActivity.this.rewardedAd = rewardedAd; Log.d(TAG, "onAdLoaded"); MainActivity.this.isLoading = false; Toast.makeText(MainActivity.this, "onAdLoaded", Toast.LENGTH_SHORT).show(); ...
Main Activity. Inflates main activity xml.
onAdLoaded
java
googleads/googleads-mobile-android-examples
java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
Apache-2.0
private void addCoins(int coins) { coinCount += coins; coinCountText.setText("Coins: " + coinCount); }
Main Activity. Inflates main activity xml.
addCoins
java
googleads/googleads-mobile-android-examples
java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
Apache-2.0
private void startGame() { // Hide the retry button, load the ad, and start the timer. retryButton.setVisibility(View.INVISIBLE); showVideoButton.setVisibility(View.INVISIBLE); createTimer(COUNTER_TIME); gamePaused = false; gameOver = false; }
Main Activity. Inflates main activity xml.
startGame
java
googleads/googleads-mobile-android-examples
java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
Apache-2.0
private void createTimer(long time) { final TextView textView = findViewById(R.id.timer); if (countDownTimer != null) { countDownTimer.cancel(); } countDownTimer = new CountDownTimer(time * 1000, 50) { @Override public void onTick(long millisUnitFinished) { ...
Main Activity. Inflates main activity xml.
createTimer
java
googleads/googleads-mobile-android-examples
java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
Apache-2.0
@Override public void onTick(long millisUnitFinished) { timeRemaining = ((millisUnitFinished / 1000) + 1); textView.setText("seconds remaining: " + timeRemaining); }
Main Activity. Inflates main activity xml.
onTick
java
googleads/googleads-mobile-android-examples
java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
Apache-2.0
@Override public void onFinish() { if (rewardedAd != null) { showVideoButton.setVisibility(View.VISIBLE); } textView.setText("You Lose!"); addCoins(GAME_OVER_REWARD); retryButton.setVisibility(View.VISIBLE); gameOver = true;...
Main Activity. Inflates main activity xml.
onFinish
java
googleads/googleads-mobile-android-examples
java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
Apache-2.0
private void showRewardedVideo() { if (rewardedAd == null) { Log.d("TAG", "The rewarded ad wasn't ready yet."); return; } showVideoButton.setVisibility(View.INVISIBLE); rewardedAd.setFullScreenContentCallback( new FullScreenContentCallback() { @Override public vo...
Main Activity. Inflates main activity xml.
showRewardedVideo
java
googleads/googleads-mobile-android-examples
java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/RewardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
Apache-2.0