MobileAds

public class MobileAds 

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.

Summary

Constants

static final String
ERROR_DOMAIN = "com.google.android.gms.ads"

Default error domain name for the Google Mobile Ads SDK.

Public methods

static void

Call before initialize or the first ad request to disable mediation adapter initialization.

static @ Nullable InitializationStatus

Gets the SDK initialization status.

static @ NonNull RequestConfiguration

Gets the global RequestConfiguration .

static VersionInfo

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

static void
@ RequiresPermission (value = Manifest.permission.INTERNET)
initialize ( Context  context)

Initializes the Google Mobile Ads SDK.

static void

Initializes the Google Mobile Ads SDK.

static void

Opens the ad inspector UI.

static void
openDebugMenu ( Context  context,  String  adUnitId)

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 @ Nullable CustomTabsSession
registerCustomTabsSession (
    @ NonNull Context  context,
    @ NonNull CustomTabsClient  client,
    @ NonNull String  origin,
    @ Nullable CustomTabsCallback  callback
)

Registers a CustomTabsClient with the Google Mobile Ads SDK to improve in-app ad monetization of ads within this CustomTabsSession .

static void

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

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 (
    @ NonNull RequestConfiguration  requestConfiguration
)

Sets the global RequestConfiguration that will be used for every AdRequest during the app's session.

static void
startPreload (
    @ NonNull Context  context,
    @ NonNull List < PreloadConfiguration > preloadConfigurations,
    @ NonNull PreloadCallback  preloadCallback
)

This method is deprecated.

Use start or start instead.

Constants

ERROR_DOMAIN

public static final  String 
 ERROR_DOMAIN 
= "com.google.android.gms.ads"

Default error domain name for the Google Mobile Ads SDK.

Public methods

disableMediationAdapterInitialization

public static void  disableMediationAdapterInitialization 
( Context 
 context)

Call before initialize or the first ad request to disable mediation adapter initialization. This method is a noop once initialize 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).

getInitializationStatus

public static @ Nullable 
 InitializationStatus 
 getInitializationStatus 
()

Gets the SDK initialization status.

getRequestConfiguration

public static @ NonNull 
 RequestConfiguration 
 getRequestConfiguration 
()

Gets the global RequestConfiguration .

getVersion

public static  VersionInfo 
 getVersion 
()

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

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

initialize

@ RequiresPermission 
(value = Manifest.permission.INTERNET)
public static void  initialize ( 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  context

The Context the SDK is running in.

initialize

public static void  initialize 
( Context 
 context,  OnInitializationCompleteListener 
 listener)

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  context

The activity Context the SDK is running in.

OnInitializationCompleteListener  listener

A callback to be invoked upon initialization completion.

openAdInspector

public static void  openAdInspector 
( Context 
 context,  OnAdInspectorClosedListener 
 listener)

Opens the ad inspector UI.

openDebugMenu

public static void  openDebugMenu 
( Context 
 context,  String 
 adUnitId)

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

Parameters
Context  context

The activity Context the SDK is running in.

String  adUnitId

Any Ad Manager ad unit ID associated with your app.

putPublisherFirstPartyIdEnabled

public 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.

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

initialize must be called prior to this function.

Parameters
boolean enabled

boolean true if the publisher first-party ID is enabled, false otherwise.

Returns
boolean

true if the decision is persisted successfully. False if it fails to be persisted.

registerCustomTabsSession

public static @ Nullable 
 CustomTabsSession 
 registerCustomTabsSession 
(
    @ NonNull Context  context,
    @ NonNull CustomTabsClient  client,
    @ NonNull String  origin,
    @ Nullable CustomTabsCallback  callback
)

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

Parameters
@ NonNull Context  context

The Context the SDK is running in.

@ NonNull CustomTabsClient  client

CustomTabsClient used to create the CustomTabsSession instance.

@ NonNull String  origin

String used as origin on the Digital Asset Link for verification.

@ Nullable CustomTabsCallback  callback

optional CustomTabsCallback to receive callbacks from .

Returns
@ Nullable CustomTabsSession

CustomTabsSession instance to be used for Custom Tabs Intent when opening a Custom Tabs page.

registerWebView

public static void  registerWebView 
(@ NonNull 
 WebView 
 webview)

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

setAppMuted

public static void  setAppMuted 
(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
boolean muted

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

setAppVolume

public static void  setAppVolume 
(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
float volume

the volume as a float from 0 (muted) to 1.0 (full media volume). Defaults to 1.0

Throws
java.lang.IllegalArgumentException

if volume is out of the valid range

setRequestConfiguration

public static void  setRequestConfiguration 
(
    @ NonNull RequestConfiguration  requestConfiguration
)

Sets the global RequestConfiguration that will be used for every AdRequest during the app's session.

startPreload

public static void    startPreload 
 
 
(
    @ NonNull Context  context,
    @ NonNull List < PreloadConfiguration > preloadConfigurations,
    @ NonNull PreloadCallback  preloadCallback
)

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.

Parameters
@ NonNull Context  context

The Context the SDK is running in.

@ NonNull List < PreloadConfiguration > preloadConfigurations

The configurations to preload ads.

@ NonNull PreloadCallback  preloadCallback

A callback to be invoked when ad availability changes for each preload configuration.

Create a Mobile Website
View Site in Mobile | Classic
Share by: