### Java Example Source: https://developers.google.com/admob/android/response-info Example of how to retrieve AdapterResponseInfo details in Java. ```APIDOC ## Java Example ```java @Override public void onAdLoaded() { AdapterResponseInfo loadedAdapterResponseInfo = adView.getResponseInfo().getLoadedAdapterResponseInfo(); AdError adError = loadedAdapterResponseInfo.getAdError(); String adSourceId = loadedAdapterResponseInfo.getAdSourceId(); String adSourceInstanceId = loadedAdapterResponseInfo.getAdSourceInstanceId(); String adSourceInstanceName = loadedAdapterResponseInfo.getAdSourceInstanceName(); String adSourceName = loadedAdapterResponseInfo.getAdSourceName(); String adapterClassName = loadedAdapterResponseInfo.getAdapterClassName(); Bundle credentials = loadedAdapterResponseInfo.getCredentials(); long latencyMillis = loadedAdapterResponseInfo.getLatencyMillis(); } ``` ``` -------------------------------- ### start (with callback) Source: https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/rewarded/RewardedAdPreloader Starts preloading ads with a callback for notifications on ad availability changes. ```APIDOC ## start ### Description Starts preloading ads for the given `preloadId`, `PreloadConfiguration`, and `PreloadCallbackV2`. The SDK continues preloading ads until the number of ads specified by `getBufferSize` is reached, attempting to keep the buffer full throughout the session. For each ad request, the SDK triggers either an `onAdPreloaded` callback upon successful preloading or an `onAdFailedToPreload` callback if preloading fails. The SDK automatically retries failed requests. If a `PreloadConfiguration` has already started with the given `preloadId`, this method does nothing and returns `false`. ### Method `static fun start(preloadId: String!, preloadConfiguration: PreloadConfiguration!, preloadCallback: PreloadCallbackV2!): Boolean` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```java // No direct request body for this method ``` ### Response #### Success Response (200) - `Boolean`: `true` if preloading started, `false` if the preloadId is in-use. #### Response Example ```json { "example": "true or false" } ``` ``` -------------------------------- ### Kotlin Example Source: https://developers.google.com/admob/android/response-info Example of how to retrieve AdapterResponseInfo details in Kotlin. ```APIDOC ## Kotlin Example ```kotlin override fun onAdLoaded() { val loadedAdapterResponseInfo = adView.responseInfo?.loadedAdapterResponseInfo val adError = loadedAdapterResponseInfo?.adError val adSourceId = loadedAdapterResponseInfo?.adSourceId val adSourceInstanceId = loadedAdapterResponseInfo?.adSourceInstanceId val adSourceInstanceName = loadedAdapterResponseInfo?.adSourceInstanceName val adSourceName = loadedAdapterResponseInfo?.adSourceName val adapterClassName = loadedAdapterResponseInfo?.adapterClassName val credentials = loadedAdapterResponseInfo?.credentials val latencyMillis = loadedAdapterResponseInfo?.latencyMillis } ``` ``` -------------------------------- ### start (With Callback) Source: https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/rewarded/RewardedAdPreloader?hl=pt-br Starts the ad preloading process with a callback to handle success or failure events. ```APIDOC ## start ### Description Starts preloading ads with a callback to monitor availability changes. The SDK automatically retries failed requests. ### Parameters - **preloadId** (String!) - Required - Unique identifier for the configuration. - **preloadConfiguration** (PreloadConfiguration!) - Required - The configuration settings for preloading. - **preloadCallback** (PreloadCallbackV2!) - Required - Callback invoked when ad availability changes. ### Response - **Boolean** - Returns true if preloading started, false if the preloadId is already in use. ``` -------------------------------- ### start (Configuration Only) Source: https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/rewarded/RewardedAdPreloader?hl=pt-br Starts the ad preloading process for a specific configuration without a callback. ```APIDOC ## start ### Description Starts preloading ads for the specified preloadId and configuration. The SDK maintains the buffer size throughout the session. ### Parameters - **preloadId** (String!) - Required - Unique identifier for the configuration. - **preloadConfiguration** (PreloadConfiguration!) - Required - The configuration settings for preloading. ### Response - **Boolean** - Returns true if preloading started, false if the preloadId is already in use. ``` -------------------------------- ### Start Preload Ads (Deprecated) Source: https://developers.google.com/admob/android/reference/com/google/android/gms/ads/MobileAds This method is deprecated. Use `start` or `start` instead. It was used for starting preloading ads for the given configurations. ```APIDOC ## startPreload (Deprecated) ### Description **This method is deprecated.** Use `start` or `start` instead. Starts preloading ads for the given configurations. Ad preloading APIs are in a limited alpha. Please reach out to your account manager for more information. ### Method `public static void ~~startPreload~~(@NonNull Context context, @NonNull List preloadConfigurations, @NonNull PreloadCallback preloadCallback)` ### Endpoint None ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **context** (Context) - Required - The `Context` the SDK is running in. - **preloadConfigurations** (List) - Required - The configurations to preload ads. - **preloadCallback** (PreloadCallback) - Required - A callback to be invoked when ad availability changes for each preload configuration. ### Request Example None ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### start (PreloadConfiguration with Callback) Source: https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/interstitial/InterstitialAdPreloader Starts the ad preloading process with an associated callback to monitor ad availability changes. ```APIDOC ## start ### Description Starts preloading ads for the given preloadId, PreloadConfiguration, and PreloadCallbackV2. The SDK triggers onAdPreloaded or onAdFailedToPreload callbacks for each request. ### Parameters #### Parameters - **preloadId** (String!) - Required - A string that uniquely identifies this PreloadConfiguration. - **preloadConfiguration** (PreloadConfiguration!) - Required - The configuration that dictates how ads are preloaded. - **preloadCallback** (PreloadCallbackV2!) - Required - A callback to be invoked when ad availability changes. ### Response - **Boolean** - true if preloading started, false if the preloadId is in-use. ``` -------------------------------- ### start (PreloadConfiguration) Source: https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/interstitial/InterstitialAdPreloader Starts the ad preloading process for a specific configuration identified by a unique preloadId. ```APIDOC ## start ### Description Starts preloading ads for the given preloadId and PreloadConfiguration. The SDK continues preloading until the buffer size is reached. If the preloadId is already in use, this method returns false. ### Parameters #### Parameters - **preloadId** (String!) - Required - A string identifier for this PreloadConfiguration. - **preloadConfiguration** (PreloadConfiguration!) - Required - The configuration for preloading ads. ### Response - **Boolean** - true if preloading started, false if the preloadId is in-use. ``` -------------------------------- ### start (without callback) Source: https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/rewarded/RewardedAdPreloader Starts preloading ads for a given preload ID and configuration. The SDK attempts to keep the buffer full. ```APIDOC ## start ### Description Starts preloading ads for the given `preloadId` and `PreloadConfiguration`. The SDK continues preloading ads until the number of ads specified by `getBufferSize` is reached, attempting to keep the buffer full throughout the session. If a `PreloadConfiguration` was already started with `preloadId`, this method becomes a no-op and returns `false`. ### Method `static fun start(preloadId: String!, preloadConfiguration: PreloadConfiguration!): Boolean` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```java // No direct request body for this method ``` ### Response #### Success Response (200) - `Boolean`: `true` if preloading started, `false` if the preloadId is in-use. #### Response Example ```json { "example": "true or false" } ``` ``` -------------------------------- ### Start Ad Preloading (Deprecated) Source: https://developers.google.com/admob/android/reference/com/google/android/gms/ads/MobileAds Initiates ad preloading for specified configurations. This method is deprecated; use the recommended start APIs instead. ```java public static void startPreload( @NonNull Context context, @NonNull List preloadConfigurations, @NonNull PreloadCallback preloadCallback ) ``` -------------------------------- ### Start Preloading Ads with Configuration and Callback Source: https://developers.google.com/admob/android/reference/com/google/android/gms/ads/appopen/AppOpenAdPreloader Initiates the preloading of app open ads with a specific configuration and a callback for preloading events. Returns true if preloading was successfully started. ```java public static boolean start( String preloadId, PreloadConfiguration preloadConfiguration, PreloadCallbackV2 preloadCallback ) ``` -------------------------------- ### Start Ad Preloading (with Callback) Source: https://developers.google.com/admob/android/reference/com/google/android/gms/ads/rewarded/RewardedAdPreloader Starts preloading ads with a preload ID, configuration, and a callback for ad availability changes. ```APIDOC ## start (with Callback) ### Description Starts preloading ads for the given `preloadId`, `PreloadConfiguration`, and `PreloadCallbackV2`. The SDK continues preloading ads until the number of ads specified by `getBufferSize` is reached, attempting to keep the buffer full throughout the session. For each ad request, the SDK triggers either an `onAdPreloaded` callback upon successful preloading or an `onAdFailedToPreload` callback if preloading fails. The SDK automatically retries failed requests. If a `PreloadConfiguration` has already started with the given `preloadId`, this method does nothing and returns `false`. ### Method `public static boolean start(String preloadId, PreloadConfiguration preloadConfiguration, PreloadCallbackV2 preloadCallback)` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```java PreloadConfiguration config = new PreloadConfiguration.Builder().setBufferSize(3).build(); AdMobManager.start("your_preload_id", config, new PreloadCallbackV2() { @Override public void onAdPreloaded(String preloadId) { // Handle preloaded ad } @Override public void onAdFailedToPreload(String preloadId, AdError adError) { // Handle preloading failure } }); ``` ### Response #### Success Response (200) - **boolean** - `true` if preloading started, `false` if the preloadId is in-use. #### Response Example ```json { "started": true } ``` ``` -------------------------------- ### Start Ad Preloading (Deprecated) Source: https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/MobileAds Initiates ad preloading for specific configurations. This API is in limited alpha and is currently deprecated in favor of other start methods. ```kotlin java-static fun ~~startPreload~~( context: Context, preloadConfigurations: (Mutable)List, preloadCallback: PreloadCallback ): Unit ``` -------------------------------- ### Start Preloading Ads with Configuration Source: https://developers.google.com/admob/android/reference/com/google/android/gms/ads/appopen/AppOpenAdPreloader Initiates the preloading of app open ads using the provided preload ID and configuration. Returns true if preloading was successfully started. ```java public static boolean start(String preloadId, PreloadConfiguration preloadConfiguration) ``` -------------------------------- ### RewardedAd Implementation Example Source: https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/rewarded/RewardedAd This code example demonstrates how to implement the RewardedAd class in an Android Activity using Kotlin or Java. It covers loading an ad, setting up callbacks for ad events, and showing the ad to the user. ```APIDOC ## RewardedAd Implementation Example ### Description This example shows how to load and display a rewarded ad in an Android application. ### Method ```java public class MainActivity extends AppCompatActivity { private RewardedAd rewardedAd; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); FullScreenContentCallback fullScreenContentCallback = new FullScreenContentCallback() { @Override public void onAdShowedFullScreenContent() { // Code to be invoked when the ad showed full screen content. } @Override public void onAdDismissedFullScreenContent() { rewardedAd = null; // Code to be invoked when the ad dismissed full screen content. } }; RewardedAd.load( this, "adUnitId", new AdRequest.Builder().build(), new RewardedAdLoadCallback() { @Override public void onAdLoaded(RewardedAd ad) { findViewById(R.id.display_button).setVisibility(View.VISIBLE); rewardedAd = ad; rewardedAd.setFullScreenContentCallback(fullScreenContentCallback); } }); } public void onDisplayButtonClicked(View view) { if (rewardedAd != null) { rewardedAd.show( this, new OnUserEarnedRewardListener() { @Override public void onUserEarnedReward(@NonNull RewardItem rewardItem) { Toast.makeText( MainActivity.this, "onRewarded! currency: " + rewardItem.getType() + " amount: " + rewardItem.getAmount(), Toast.LENGTH_SHORT).show(); } }); } } } ``` ### Request Example ```json { "adUnitId": "ca-app-pub-3940256099942544/5224748851", "adRequest": {} } ``` ### Response #### Success Response (200) - **rewardedAd** (RewardedAd) - The loaded rewarded ad object. #### Response Example ```json { "rewardedAd": "RewardedAd object" } ``` ``` -------------------------------- ### Start Ad Preloading (Configuration Only) Source: https://developers.google.com/admob/android/reference/com/google/android/gms/ads/appopen/AppOpenAdPreloader Initiates the preloading of ads for a specified preload ID and configuration. The SDK attempts to maintain a buffer of ads as defined by `getBufferSize`. If preloading has already started for the given `preloadId`, this method is a no-op. ```APIDOC ## start (PreloadConfiguration) ### Description Starts preloading ads for the given `preloadId` and `PreloadConfiguration`. The SDK continues preloading ads until the number of ads specified by `getBufferSize` is reached, attempting to keep the buffer full throughout the session. If a `PreloadConfiguration` was already started with `preloadId`, this method becomes a no-op and returns `false`. ### Method `public static boolean start(String preloadId, PreloadConfiguration preloadConfiguration)` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```java PreloadConfiguration config = new PreloadConfiguration.Builder().setBufferSize(3).build(); boolean started = AdMobAppOpenAds.start("your_preload_id", config); ``` ### Response #### Success Response (200) - **boolean** - `true` if preloading started, `false` if the `preloadId` is in-use. #### Response Example ```java // Preloading started successfully true // Preloading already in progress for this preloadId false ``` ``` -------------------------------- ### Start Ad Preloading with Callback Source: https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/rewarded/RewardedAdPreloader?hl=pt-br Starts preloading ads with a specific preload ID, configuration, and a callback to notify about changes in ad availability. The SDK automatically retries failed requests. Returns false if the preload ID is already in use. ```kotlin fun start( preloadId: String!, preloadConfiguration: PreloadConfiguration!, preloadCallback: PreloadCallbackV2! ): Boolean ``` -------------------------------- ### Start Ad Preloading (With Callback) Source: https://developers.google.com/admob/android/reference/com/google/android/gms/ads/appopen/AppOpenAdPreloader Initiates the preloading of ads with a specified preload ID, configuration, and a callback for preloading events. The SDK manages ad preloading and retries failed requests. If preloading has already started for the given `preloadId`, this method is a no-op. ```APIDOC ## start (PreloadConfiguration, PreloadCallbackV2) ### Description Starts preloading ads for the given `preloadId`, `PreloadConfiguration`, and `PreloadCallbackV2`. The SDK continues preloading ads until the number of ads specified by `getBufferSize` is reached, attempting to keep the buffer full throughout the session. For each ad request, the SDK triggers either an `onAdPreloaded` callback upon successful preloading or an `onAdFailedToPreload` callback if preloading fails. The SDK automatically retries failed requests. If a `PreloadConfiguration` has already started with the given `preloadId`, this method does nothing and returns `false`. ### Method `public static boolean start(String preloadId, PreloadConfiguration preloadConfiguration, PreloadCallbackV2 preloadCallback)` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```java PreloadConfiguration config = new PreloadConfiguration.Builder().setBufferSize(3).build(); AdEventListener listener = new AdEventListener() { @Override public void onAdPreloaded(String preloadId) { // Handle successful preloading } @Override public void onAdFailedToPreload(String preloadId, AdError error) { // Handle preloading failure } }; boolean started = AdMobAppOpenAds.start("your_preload_id", config, listener); ``` ### Response #### Success Response (200) - **boolean** - `true` if preloading started, `false` if the `preloadId` is in-use. #### Response Example ```java // Preloading started successfully true // Preloading already in progress for this preloadId false ``` ``` -------------------------------- ### toString Method Example Source: https://developers.google.com/admob/android/reference/com/google/android/gms/ads/LoadAdError Example of how to get a string representation of a LoadAdError. ```APIDOC ## Method: toString ### Description Returns a log friendly string version of this object. ### Returns - **String** - A string representation of the LoadAdError. ### Request Example ```java String errorString = loadAdError.toString(); Log.d("AdError", errorString); ``` ``` -------------------------------- ### Get SDK Version (Kotlin) Source: https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/MobileAds Retrieves the external version of the Google Mobile Ads SDK, for example, '20.6.0'. Use this to check the current SDK version. ```kotlin MobileAds.getVersion() ``` -------------------------------- ### Console Output Example for Network Logs Source: https://developers.google.com/admob/android/network-tracing?hl=es-419 Standard console log messages for network activity. Logs start with 'GMA Debug BEGIN', 'GMA Debug CONTENT', or 'GMA Debug FINISH'. Content is split into multiple lines if too long, with each line starting with 'GMA Debug CONTENT'. ```log I/Ads ( 4660): GMA Debug BEGIN I/Ads ( 4660): GMA Debug CONTENT {"timestamp":1510679993741,...} I/Ads ( 4660): GMA Debug FINISH ``` -------------------------------- ### Example Usage Source: https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/h5/H5AdsWebViewClient Demonstrates how to initialize and use the H5AdsWebViewClient in an Android application. ```APIDOC ### Example code: ```java public void onCreate(Bundle savedInstanceState) { ... // Initialize early to reduce latency on the session's first ad request. MobileAds.initialize(this); WebView myWebView = findViewById(R.id.my_webview); // JavaScript must be enabled. WebSettings settings = myWebView.getSettings(); settings.setJavaScriptEnabled(true); H5AdsWebViewClient h5Client = new H5AdsWebViewClient(this, myWebView); // (Optional) any existing WebViewClient WebViewClient myClient = ...; h5Client.setDelegateWebViewClient(myClient); webView.setWebViewClient(h5Client); } ``` ``` -------------------------------- ### getResponseInfo Method Example Source: https://developers.google.com/admob/android/reference/com/google/android/gms/ads/LoadAdError Example of how to retrieve the ResponseInfo from a LoadAdError. ```APIDOC ## Method: getResponseInfo ### Description Gets the ResponseInfo of the error. ### Returns - **ResponseInfo** - Information about the ad response, or null if not available. ### Request Example ```java ResponseInfo responseInfo = loadAdError.getResponseInfo(); if (responseInfo != null) { // Process response info } ``` ``` -------------------------------- ### Initialize H5AdsWebViewClient in Activity Source: https://developers.google.com/admob/android/reference/com/google/android/gms/ads/h5/H5AdsWebViewClient Example showing how to initialize the Mobile Ads SDK and configure a WebView with H5AdsWebViewClient. ```java public void onCreate(Bundle savedInstanceState) { ... // Initialize early to reduce latency on the session's first ad request. MobileAds.initialize(this); WebView myWebView = findViewById(R.id.my_webview); // JavaScript must be enabled. WebSettings settings = myWebView.getSettings(); settings.setJavaScriptEnabled(true); H5AdsWebViewClient h5Client = new H5AdsWebViewClient(this, myWebView); // (Optional) any existing WebViewClient WebViewClient myClient = ...; h5Client.setDelegateWebViewClient(myClient); webView.setWebViewClient(h5Client); } ``` -------------------------------- ### LoadAdError Constructor Example Source: https://developers.google.com/admob/android/reference/com/google/android/gms/ads/LoadAdError Example of how to create a LoadAdError instance. ```APIDOC ## Constructor: LoadAdError ### Parameters - **code** (int) - Required - The error code. - **message** (String) - Required - A message detailing the error. - **domain** (String) - Required - The error domain. - **cause** (AdError) - Optional - The cause of this error or `null` if the cause is nonexistent or unknown. - **responseInfo** (ResponseInfo) - Optional - Ad response information. ### Request Example ```java LoadAdError loadAdError = new LoadAdError( 102, "Some error message", "Google", null, null ); ``` ``` -------------------------------- ### Notify video start Source: https://developers.google.com/admob/android/reference/com/google/android/gms/ads/mediation/MediationRewardedAdCallback Signals that the rewarded ad has started playing. ```java abstract void onVideoStart() ``` -------------------------------- ### Implementing AdView in an Activity Source: https://developers.google.com/admob/android/reference/com/google/android/gms/ads/AdView?hl=es Example showing how to programmatically create an AdView, configure it, and manage its lifecycle within an Activity. ```java public class MyActivity extends Activity { private AdView mAdView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); // Create a banner ad. The ad size and ad unit ID must be set before calling loadAd. mAdView = new AdView(this); mAdView.setAdSize(AdSize.BANNER); mAdView.setAdUnitId("myAdUnitId"); // Create an ad request. AdRequest.Builder adRequestBuilder = new AdRequest.Builder(); // Add the AdView to the view hierarchy. layout.addView(mAdView); // Start loading the ad. mAdView.loadAd(adRequestBuilder.build()); setContentView(layout); } @Override public void onResume() { super.onResume(); // Resume the AdView. mAdView.resume(); } @Override public void onPause() { // Pause the AdView. mAdView.pause(); super.onPause(); } @Override public void onDestroy() { // Destroy the AdView. mAdView.destroy(); super.onDestroy(); } } ``` -------------------------------- ### initialize Source: https://developers.google.com/admob/android/reference/com/google/android/gms/ads/mediation/Adapter Initializes a third-party adapter and SDK. ```APIDOC ## initialize ### Description Called by the Google Mobile Ads SDK to initialize a third party adapter and SDK. This method is invoked shortly after the app initializes the Google Mobile Ads SDK. ### Parameters - **context** (Context) - Required - The context the publisher provides in initialize - **callback** (InitializationCompleteCallback) - Required - Callback to be invoked when the adapter has finished initialization. - **configurations** (List) - Required - A list of MediationConfiguration objects configured for this adapter in the Google AdMob or Google Ad Manager UI. ``` -------------------------------- ### Adapter Initialization and Versioning Source: https://developers.google.com/admob/android/reference/com/google/android/gms/ads/mediation/rtb/RtbAdapter Methods for initializing the adapter and retrieving SDK/adapter version information. ```APIDOC ## Inherited methods from com.google.android.gms.ads.mediation.Adapter ### getSDKVersionInfo * **Description**: Returns the version of the third party SDK built into the app. * **Method**: abstract * **Return Type**: VersionInfo ### getVersionInfo * **Description**: Returns the version of the mediation adapter. * **Method**: abstract * **Return Type**: VersionInfo ### initialize * **Description**: Called by the Google Mobile Ads SDK to initialize a third party adapter and SDK. * **Method**: abstract * **Parameters**: * `context` (Context) - Required - The application context. * `callback` (InitializationCompleteCallback) - Required - Callback for initialization completion. * `configurations` (List) - Required - List of mediation configurations. ``` -------------------------------- ### reportTouchEvent Data Example Source: https://developers.google.com/admob/android/reference/com/google/android/gms/ads/formats/NativeAd Example JSON representation of the touchEventData Bundle for the deprecated reportTouchEvent method. ```json { "x": "100", "y": "50", "duration_millis": "500" } ``` -------------------------------- ### Console output example Source: https://developers.google.com/admob/android/network-tracing Example of the standard console log format used for network tracing. ```text I/Ads ( 4660): GMA Debug BEGIN I/Ads ( 4660): GMA Debug CONTENT {"timestamp":1510679993741,...} I/Ads ( 4660): GMA Debug FINISH ``` -------------------------------- ### Inicializa el adaptador de eventos personalizados Source: https://developers.google.com/admob/android/custom-events/overview?hl=es-419 Implementa el método initialize para configurar el SDK de terceros. Asegúrate de invocar el callback de éxito una vez finalizada la inicialización. ```java package com.google.ads.mediation.sample.customevent; import com.google.android.gms.ads.mediation.Adapter; import com.google.android.gms.ads.mediation.InitializationCompleteCallback; import com.google.android.gms.ads.mediation.MediationConfiguration; public class SampleAdNetworkCustomEvent extends Adapter { private static final String SAMPLE_AD_UNIT_KEY = "parameter"; @Override public void initialize(Context context, InitializationCompleteCallback initializationCompleteCallback, List mediationConfigurations) { // This is where you will initialize the SDK that this custom // event is built for. Upon finishing the SDK initialization, // call the completion handler with success. initializationCompleteCallback.onInitializationSucceeded(); } } ``` ```kotlin package com.google.ads.mediation.sample.customevent import com.google.android.gms.ads.mediation.Adapter import com.google.android.gms.ads.mediation.InitializationCompleteCallback import com.google.android.gms.ads.mediation.MediationConfiguration class SampleCustomEvent : Adapter() { private val SAMPLE_AD_UNIT_KEY = "parameter" override fun initialize( context: Context, initializationCompleteCallback: InitializationCompleteCallback, mediationConfigurations: List ) { // This is where you will initialize the SDK that this custom // event is built for. Upon finishing the SDK initialization, // call the completion handler with success. initializationCompleteCallback.onInitializationSucceeded() } } ``` -------------------------------- ### Start Game Logic Source: https://developers.google.com/admob/android/interstitial?hl=ca Hides the retry button, starts the game timer, and sets game state flags. ```java private void startGame() { // Hide the button, and kick off the timer. retryButton.setVisibility(View.INVISIBLE); createTimer(GAME_LENGTH_MILLISECONDS); gamePaused = false; gameOver = false; } ``` -------------------------------- ### Initialize and Load Interstitial Ads in MainActivity Source: https://developers.google.com/admob/android/interstitial?hl=de This snippet demonstrates the setup of an Android Activity, including consent gathering, SDK initialization, and the interstitial ad loading process. ```kotlin package com.google.android.gms.example.interstitialexample import android.os.Bundle import android.os.CountDownTimer import android.util.Log import android.view.Menu import android.view.MenuItem import android.view.View import android.widget.PopupMenu import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat import com.google.android.gms.ads.* import com.google.android.gms.ads.interstitial.InterstitialAd import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback import com.google.android.gms.example.interstitialexample.databinding.ActivityMainBinding import java.util.concurrent.atomic.AtomicBoolean import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch class MainActivity : AppCompatActivity() { private val isMobileAdsInitializeCalled = AtomicBoolean(false) private lateinit var binding: ActivityMainBinding private lateinit var googleMobileAdsConsentManager: GoogleMobileAdsConsentManager private var interstitialAd: InterstitialAd? = null private var countdownTimer: CountDownTimer? = null private var gamePaused = false private var gameOver = false private var adIsLoading: Boolean = false private var timerMilliseconds = 0L override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) val view = binding.root setContentView(view) setSupportActionBar(binding.toolBar) ViewCompat.setOnApplyWindowInsetsListener(binding.root) { view, insets -> val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()) view.setPadding(systemBars.left, 0, systemBars.right, systemBars.bottom) insets } // Log the Mobile Ads SDK version. Log.d(TAG, "Google Mobile Ads SDK Version: " + MobileAds.getVersion()) googleMobileAdsConsentManager = GoogleMobileAdsConsentManager.getInstance(this) googleMobileAdsConsentManager.gatherConsent(this) { consentError -> if (consentError != null) { // Consent not obtained in current session. Log.w(TAG, "${consentError.errorCode}: ${consentError.message}") } // Kick off the first play of the "game". startGame() if (googleMobileAdsConsentManager.canRequestAds) { initializeMobileAdsSdk() } if (googleMobileAdsConsentManager.isPrivacyOptionsRequired) { // Regenerate the options menu to include a privacy setting. invalidateOptionsMenu() } } // This sample attempts to load ads using consent obtained in the previous session. if (googleMobileAdsConsentManager.canRequestAds) { initializeMobileAdsSdk() } // Create the "retry" button, which triggers an interstitial between game plays. binding.retryButton.visibility = View.INVISIBLE binding.retryButton.setOnClickListener { showInterstitial() } } override fun onCreateOptionsMenu(menu: Menu?): Boolean { menuInflater.inflate(R.menu.action_menu, menu) return super.onCreateOptionsMenu(menu) } override fun onOptionsItemSelected(item: MenuItem): Boolean { val menuItemView = findViewById(item.itemId) val activity = this PopupMenu(this, menuItemView).apply { menuInflater.inflate(R.menu.popup_menu, menu) menu .findItem(R.id.privacy_settings) .setVisible(googleMobileAdsConsentManager.isPrivacyOptionsRequired) show() setOnMenuItemClickListener { popupMenuItem -> when (popupMenuItem.itemId) { R.id.privacy_settings -> { pauseGame() // Handle changes to user consent. googleMobileAdsConsentManager.showPrivacyOptionsForm(activity) { formError -> if (formError != null) { Toast.makeText(activity, formError.message, Toast.LENGTH_SHORT).show() } resumeGame() } true } R.id.ad_inspector -> { MobileAds.openAdInspector(activity) { error -> // Error will be non-null if ad inspector closed due to an error. error?.let { Toast.makeText(activity, it.message, Toast.LENGTH_SHORT).show() } } true } // Handle other branches here. else -> false } } return super.onOptionsItemSelected(item) } } private fun loadAd() { // Request a new ad if one isn't already loaded. if (adIsLoading || interstitialAd != null) { return } adIsLoading = true InterstitialAd.load( this, AD_UNIT_ID, AdRequest.Builder().build(), object : InterstitialAdLoadCallback() { override fun onAdLoaded(ad: InterstitialAd) { Log.d(TAG, "Ad was loaded.") interstitialAd = ad adIsLoading = false ``` -------------------------------- ### Static Registration and Initialization Source: https://developers.google.com/admob/android/reference/com/google/android/gms/ads/BaseAdView?hl=ar Static methods for registration and initialization. ```APIDOC ## registerCalledFromWrongThreadListener ### Description Registers a listener for calls from the wrong thread. ### Method static void ### Endpoint N/A (Static method) ### Parameters - **p** (View.CalledFromWrongThreadListener) - Description not provided ``` -------------------------------- ### Start Ad Preloading (Basic) Source: https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/rewarded/RewardedAdPreloader?hl=pt-br Initiates the preloading of ads for a specified preload ID and configuration. The SDK attempts to keep the ad buffer full. Returns false if the preload ID is already in use. ```kotlin fun start(preloadId: String!, preloadConfiguration: PreloadConfiguration!): Boolean ``` -------------------------------- ### Start Game Logic Source: https://developers.google.com/admob/android/interstitial?hl=it Hides the retry button, starts a game timer, and resets game state variables for a new game. ```java retryButton.setVisibility(View.INVISIBLE); createTimer(GAME_LENGTH_MILLISECONDS); gamePaused = false; gameOver = false; ``` -------------------------------- ### AdView Usage Example Source: https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/AdView Sample code demonstrating how to create, configure, load, and manage an AdView in an Android Activity. ```APIDOC ## AdView Usage Example ### Description This sample code demonstrates how to integrate an `AdView` into an Android Activity. It covers initialization, setting ad size and unit ID, loading an ad, and managing the ad lifecycle (resume, pause, destroy). ### Request Example ```java public class MyActivity extends Activity { private AdView mAdView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); // Create a banner ad. The ad size and ad unit ID must be set before calling loadAd. mAdView = new AdView(this); mAdView.setAdSize(AdSize.BANNER); mAdView.setAdUnitId("myAdUnitId"); // Create an ad request. AdRequest.Builder adRequestBuilder = new AdRequest.Builder(); // Add the AdView to the view hierarchy. layout.addView(mAdView); // Start loading the ad. mAdView.loadAd(adRequestBuilder.build()); setContentView(layout); } @Override public void onResume() { super.onResume(); // Resume the AdView. mAdView.resume(); } @Override public void onPause() { // Pause the AdView. mAdView.pause(); super.onPause(); } @Override public void onDestroy() { // Destroy the AdView. mAdView.destroy(); super.onDestroy(); } } ``` ### Related Attributes - `com.google.android.gms.ads.R.styleable#AdsAttrs_adSize` - `com.google.android.gms.ads.R.styleable#AdsAttrs_adUnitId` ``` -------------------------------- ### Public Constructors Source: https://developers.google.com/admob/android/reference/com/google/android/gms/ads/nativead/MediaView Information on how to instantiate the MediaView class. ```APIDOC ### Public constructors --- `MediaView(Context context)` - Creates the `MediaView`. `MediaView(Context context, AttributeSet attrs)` - Creates the `MediaView` from an XML layout. `MediaView(Context context, AttributeSet attrs, int defStyleAttr)` - Creates the `MediaView` from an XML layout. `MediaView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)` - Creates the `MediaView` from an XML layout. ``` -------------------------------- ### Start Game Logic Source: https://developers.google.com/admob/android/interstitial?hl=ca Resets the game state by hiding the retry button, starting the countdown timer, and setting game over and paused flags. ```kotlin private fun startGame() { binding.retryButton.visibility = View.INVISIBLE createTimer(GAME_LENGTH_MILLISECONDS) gamePaused = false gameOver = false } ``` -------------------------------- ### Start ad preloading Source: https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/interstitial/InterstitialAdPreloader Initiates the preloading process for a specific configuration. Returns false if the preload ID is already in use. ```kotlin java-static fun start(preloadId: String!, preloadConfiguration: PreloadConfiguration!): Boolean ``` ```kotlin java-static fun start( preloadId: String!, preloadConfiguration: PreloadConfiguration!, preloadCallback: PreloadCallbackV2! ): Boolean ``` -------------------------------- ### Start Game Logic Source: https://developers.google.com/admob/android/interstitial?hl=id Initialize game state by hiding the retry button and starting the game timer. Set game flags for `gamePaused`, `gameOver`. ```kotlin // Hide the button, and kick off the timer. private fun startGame() { binding.retryButton.visibility = View.INVISIBLE createTimer(GAME_LENGTH_MILLISECONDS) gamePaused = false gameOver = false } ``` -------------------------------- ### Get Video Duration Source: https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/mediation/NativeAdMapper Gets the video's duration. Returns zero by default. Subclasses should override this method to return a nonzero duration for video ads. ```kotlin fun getDuration(): Float ``` -------------------------------- ### H5AdsWebViewClient Constructor Source: https://developers.google.com/admob/android/reference/com/google/android/gms/ads/h5/H5AdsWebViewClient Initializes a new instance of the H5AdsWebViewClient class. ```APIDOC ## H5AdsWebViewClient Constructor ### Description Constructor for `H5AdsWebViewClient`. ### Parameters - **context** (Context) - Required - An activity or application context. - **webView** (WebView) - Required - The `WebView` that will be associated with this `H5AdsWebViewClient`. JavaScript must be enabled on the WebView. ``` -------------------------------- ### Get Adapter Initialization State (Java) Source: https://developers.google.com/admob/android/reference/com/google/android/gms/ads/initialization/AdapterStatus Gets the current initialization state of the mediation adapter. Use this to make logical decisions about the adapter's status. ```java abstract AdapterStatus.State getInitializationState() ``` -------------------------------- ### initialize Source: https://developers.google.com/admob/android/reference/com/google/android/gms/ads/MobileAds Initializes the Google Mobile Ads SDK. ```APIDOC ## initialize ### Description Initializes the Google Mobile Ads SDK. ### Parameters #### Request Body - **context** (Context) - Required - The application context. - **listener** (OnInitializationCompleteListener) - Optional - Callback to be invoked upon completion. ```