Google is committed to advancing racial equity for Black communities. See how.

MobileAds

public class MobileAds extends Object

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.

Nested Class Summary

class MobileAds.Settings This class is deprecated. This class is no longer used and has no replacement.  

Constant Summary

String ERROR_DOMAIN Default error domain name for 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.
static RequestConfiguration
static RewardedVideoAd
getRewardedVideoAdInstance(Context context)
Gets the rewarded video ad instance.
static String
getVersionString()
Gets the version string of Google Mobile Ads SDK.
static void
initialize(Context context, String applicationCode)
This method is deprecated. Use initialize(Context, OnInitializationCompleteListener) instead.
static void
initialize(Context context)
Initializes the Google Mobile Ads SDK.
static void
initialize(Context context, String applicationCode, MobileAds.Settings settings)
This method is deprecated. Use initialize(Context, OnInitializationCompleteListener) instead.
static void
initialize(Context context, OnInitializationCompleteListener listener)
Initializes the Google Mobile Ads SDK.
static void
openDebugMenu(Context context, String adUnitId)
Opens the debug menu for creative preview and troubleshooting of DFP ad units.
static void
setAppMuted(boolean muted)
Sets the current app mute state.
static void
setAppVolume(float volume)
Sets the current app volume.
static void
setRequestConfiguration(RequestConfiguration requestConfiguration)
Sets the global RequestConfiguration that will be used for every AdRequest during the app's session.

Inherited Method Summary

Constants

public static final String ERROR_DOMAIN

Default error domain name for Google Mobile Ads SDK.

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

Public Methods

public static void disableMediationAdapterInitialization (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 static InitializationStatus getInitializationStatus ()

Gets the SDK initialization status.

public static RequestConfiguration getRequestConfiguration ()

Gets the global RequestConfiguration.

public static RewardedVideoAd getRewardedVideoAdInstance (Context context)

Gets the rewarded video ad instance.

Parameters
context The Context the SDK is running in.

public static String getVersionString ()

Gets the version string of Google Mobile Ads SDK.

public static void initialize (Context context, String applicationCode)

This method is deprecated.
Use initialize(Context, OnInitializationCompleteListener) instead.

Initializes the Google Mobile Ads SDK. The SDK will configure itself.

Call this method as early as possible, and only once per application launch.

Parameters
context The Context the SDK is running in.
applicationCode The Google AdMob application code.

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 The Context the SDK is running in.

public static void initialize (Context context, String applicationCode, MobileAds.Settings settings)

This method is deprecated.
Use initialize(Context, OnInitializationCompleteListener) instead.

Initializes the Google Mobile Ads SDK. The SDK will configure itself and initialize integrated features such as Google Analytics.

Call this method as early as possible, and only once per application launch.

Parameters
context The Context the SDK is running in.
applicationCode The Google AdMob application code.
settings Additional settings for initializing the Mobile Ads SDK.

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 The activity Context the SDK is running in.
listener A callback to be invoked upon initialization completion.

public static void openDebugMenu (Context context, String adUnitId)

Opens the debug menu for creative preview and troubleshooting of DFP ad units. initialize(Context) must be called prior to this function.

Parameters
context The activity Context the SDK is running in.
adUnitId the DFP ad unit ID of the ad to preview or troubleshoot with

public static void setAppMuted (boolean muted)

Sets the current app mute state.

Parameters
muted true if the app is muted, false otherwise

public static void setAppVolume (float volume)

Sets the current app volume.

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

public static void setRequestConfiguration (RequestConfiguration requestConfiguration)

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