MobileAds

public classMobileAdsextendsObject

Class contains logic that applies to the Google Mobile Ads SDK as a whole. Right now, the only methods in it are used for initialization.

Constant Summary

String ERROR_DOMAIN Default error domain name for the Google Mobile Ads SDK.

Public Method Summary

static void
disableMediationAdapterInitialization(Context context)
Call before initialize(Context, OnInitializationCompleteListener)or the first ad request to disable mediation adapter initialization.
static InitializationStatus
getInitializationStatus()
Gets the SDK initialization status.
staticRequestConfiguration
staticVersionInfo
getVersion()
Gets the external version (for example, 20.6.0) of the Google Mobile Ads SDK.
static void
initialize(Context context)
Initializes the Google Mobile Ads SDK.
static void
initialize(Context context, OnInitializationCompleteListenerlistener)
Initializes the Google Mobile Ads SDK.
static void
openAdInspector(Context context,OnAdInspectorClosedListener listener)
Opens the ad inspector UI.
static void
openDebugMenu(Context context,StringadUnitId)
Opens the debug menu.
static boolean
putPublisherFirstPartyIdEnabled(boolean enabled)
Controls whether the Google Mobile Ads SDK publisher first-party ID, formerly known as the same app key, is enabled.
static CustomTabsSession
registerCustomTabsSession(Context context, CustomTabsClient client,Stringorigin, CustomTabsCallback callback)
Registers aCustomTabsClient with the Google Mobile Ads SDK to improve in-app ad monetization of ads within thisCustomTabsSession.
static void
registerWebView(WebView webview)
Registers aWebView with the Google Mobile Ads SDK to improve in-app ad monetization of ads within thisWebView.
static void
setAppMuted(boolean muted)
Indicates whether the application's audio is muted.
static void
setAppVolume(float volume)
Sets the application's audio volume.
static void
setRequestConfiguration(RequestConfiguration requestConfiguration)
Sets the globalRequestConfiguration that will be used for everyAdRequest during the app's session.

Inherited Method Summary

Constants

public static finalString ERROR_DOMAIN

Default error domain name for the Google Mobile Ads SDK.

Constant Value: "com.google.android.gms.ads"

Public Methods

public static voiddisableMediationAdapterInitialization(Context context)

Call before initialize(Context, OnInitializationCompleteListener)or the first ad request to disable mediation adapter initialization. This method is a noop once initialize(Context, OnInitializationCompleteListener)or the first ad request is made.

Warning: Calling this method may negatively impact your mediation performance. This method should only be called if you include mediation adapters in your app, but you don't plan to use Google mediation during this app session (for example, you are running an A/B test).

public staticInitializationStatus getInitializationStatus()

Gets the SDK initialization status.

public staticRequestConfiguration getRequestConfiguration()

Gets the globalRequestConfiguration.

public staticVersionInfo getVersion()

Gets the external version (for example, 20.6.0) of the Google Mobile Ads SDK.

initialize(Context)doesn't need to be called prior to this function.

public static voidinitialize(Context context)

Initializes the Google Mobile Ads SDK.

Call this method as early as possible after the app launches to reduce latency on the session's first ad request.

If this method is not called, the first ad request automatically initializes the Google Mobile Ads SDK.

Parameters
context TheContext the SDK is running in.

public static voidinitialize(Contextcontext, OnInitializationCompleteListenerlistener)

Initializes the Google Mobile Ads SDK.

Call this method as early as possible after the app launches to reduce latency on the session's first ad request.

If this method is not called, the first ad request automatically initializes the Google Mobile Ads SDK.

Parameters
context The activityContext the SDK is running in.
listener A callback to be invoked upon initialization completion.

public static voidopenAdInspector(Contextcontext, OnAdInspectorClosedListener listener)

Opens the ad inspector UI.

public static voidopenDebugMenu(Contextcontext, String adUnitId)

Opens the debug menu. initialize(Context)must be called prior to this function.

Parameters
context The activityContext the SDK is running in.
adUnitId Any Ad Manager ad unit ID associated with your app.

public static booleanputPublisherFirstPartyIdEnabled(boolean enabled)

Controls whether the Google Mobile Ads SDK publisher first-party ID, formerly known as the same app key, is enabled.

The ID is enabled by default. When disabled, the setting is persisted across app sessions and the ID is cleared.

initialize(Context)must be called prior to this function.

Parameters
enabled boolean true if the publisher first-party ID is enabled, false otherwise.
Returns
  • true if the decision is persisted successfully. False if it fails to be persisted.

public static CustomTabsSession registerCustomTabsSession(Contextcontext, CustomTabsClient client,Stringorigin, CustomTabsCallback callback)

Registers aCustomTabsClient with the Google Mobile Ads SDK to improve in-app ad monetization of ads within this CustomTabsSession. This will only create one instance ofCustomTabsSession and re-running this overrides the existing session.

Parameters
context TheContext the SDK is running in.
client CustomTabsClient used to create theCustomTabsSession instance.
origin String used as origin on the Digital Asset Link for verification.
callback optionalCustomTabsCallback to receive callbacks fromCustomTabsSession.
Returns
  • CustomTabsSession instance to be used for Custom Tabs Intent when opening a Custom Tabs page.

public static voidregisterWebView(WebView webview)

Registers aWebViewwith the Google Mobile Ads SDK to improve in-app ad monetization of ads within this WebView.

public static voidsetAppMuted(boolean muted)

Indicates whether the application's audio is muted. Affects initial mute state for all ads.

Warning: Muting your application reduces video ad eligibility and may reduce your app's ad revenue. You should only utilize this API if your app provides a custom mute control to the user, and you should reflect the user's mute decision in this API.

Parameters
muted true if the app is muted, false otherwise. Defaults to false.

public static voidsetAppVolume(float volume)

Sets the application's audio volume. Affects audio volumes of all ads relative to other audio output.

Warning: Lowering your app's audio volume reduces video ad eligibility and may reduce your app's ad revenue. You should only utilize this API if your app provides custom volume controls to the user, and you should reflect the user's volume choice in this API.

Parameters
volume the volume as a float from 0 (muted) to 1.0 (full media volume). Defaults to 1.0
Throws
IllegalArgumentException if volume is out of the valid range

public static voidsetRequestConfiguration(RequestConfiguration requestConfiguration)

Sets the globalRequestConfiguration that will be used for everyAdRequest during the app's session.