# MobileAds

# MobileAds


```
class MobileAds
```

<br />

*** ** * ** ***

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 |
|---|---|
| `const https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!` | `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/MobileAds#ERROR_DOMAIN() = "com.google.android.gms.ads"` Default error domain name for the Google Mobile Ads SDK. |

| ### Public functions |
|---|---|
| `java-static https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/MobileAds#disableMediationAdapterInitialization(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html!)` Call before `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/MobileAds#initialize(android.content.Context,com.google.android.gms.ads.initialization.OnInitializationCompleteListener)` or the first ad request to disable mediation adapter initialization. |
| `java-static https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/initialization/InitializationStatus?` | `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/MobileAds#getInitializationStatus()()` Gets the SDK initialization status. |
| `java-static https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/RequestConfiguration` | `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/MobileAds#getRequestConfiguration()()` Gets the global `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/RequestConfiguration`. |
| `java-static https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/VersionInfo!` | `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/MobileAds#getVersion()()` Gets the external version (for example, 20.6.0) of the Google Mobile Ads SDK. |
| `java-static https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/androidx/annotation/RequiresPermission.html(value = https://developer.android.com/reference/android/Manifest.permission.html#INTERNET) https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/MobileAds#initialize(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html!)` Initializes the Google Mobile Ads SDK. |
| `java-static https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/MobileAds#initialize(android.content.Context,com.google.android.gms.ads.initialization.OnInitializationCompleteListener)(context: https://developer.android.com/reference/android/content/Context.html!, listener: https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/initialization/OnInitializationCompleteListener!)` Initializes the Google Mobile Ads SDK. |
| `java-static https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/MobileAds#openAdInspector(android.content.Context,com.google.android.gms.ads.OnAdInspectorClosedListener)(context: https://developer.android.com/reference/android/content/Context.html!, listener: https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/OnAdInspectorClosedListener!)` Opens the ad inspector UI. |
| `java-static https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/MobileAds#openDebugMenu(android.content.Context,java.lang.String)(context: https://developer.android.com/reference/android/content/Context.html!, adUnitId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!)` Opens the debug menu. |
| `java-static https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/MobileAds#putPublisherFirstPartyIdEnabled(boolean)(enabled: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` Controls whether the Google Mobile Ads SDK publisher first-party ID, formerly known as the same app key, is enabled. |
| `java-static https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsSession.html?` | `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/MobileAds#registerCustomTabsSession(android.content.Context,androidx.browser.customtabs.CustomTabsClient,java.lang.String,androidx.browser.customtabs.CustomTabsCallback)( context: https://developer.android.com/reference/android/content/Context.html, client: https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsClient.html, origin: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, callback: https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsCallback.html? )` Registers a `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsClient.html` with the Google Mobile Ads SDK to improve in-app ad monetization of ads within this `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsSession.html`. |
| `java-static https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/MobileAds#registerWebView(android.webkit.WebView)(webview: https://developer.android.com/reference/android/webkit/WebView.html)` Registers a `https://developer.android.com/reference/android/webkit/WebView.html` with the Google Mobile Ads SDK to improve in-app ad monetization of ads within this `WebView`. |
| `java-static https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/MobileAds#setAppMuted(boolean)(muted: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` Indicates whether the application's audio is muted. |
| `java-static https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/MobileAds#setAppVolume(float)(volume: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html)` Sets the application's audio volume. |
| `java-static https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/MobileAds#setRequestConfiguration(com.google.android.gms.ads.RequestConfiguration)(requestConfiguration: https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/RequestConfiguration)` Sets the global `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/RequestConfiguration` that will be used for every `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/AdRequest` during the app's session. |
| `java-static https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `[startPreload](https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/MobileAds#startPreload(android.content.Context,java.util.List<com.google.android.gms.ads.preload.PreloadConfiguration>,com.google.android.gms.ads.preload.PreloadCallback))( context: https://developer.android.com/reference/android/content/Context.html, preloadConfigurations: (https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/preload/PreloadConfiguration!>, preloadCallback: https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/preload/PreloadCallback )` **This function is deprecated.** Use `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/preload/AdPreloader#start(java.lang.String,com.google.android.gms.ads.preload.PreloadConfiguration,com.google.android.gms.ads.preload.PreloadCallbackV2)` or `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/preload/AdPreloader#start(java.lang.String,com.google.android.gms.ads.preload.PreloadConfiguration)` instead. <br /> |

## Constants

### ERROR_DOMAIN

```
const val ERROR_DOMAIN = "com.google.android.gms.ads": String!
```

Default error domain name for the Google Mobile Ads SDK.

## Public functions

### disableMediationAdapterInitialization

```
java-static fun disableMediationAdapterInitialization(context: Context!): Unit
```

Call before `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/MobileAds#initialize(android.content.Context,com.google.android.gms.ads.initialization.OnInitializationCompleteListener)` or the first ad request to disable mediation adapter initialization. This method is a noop once `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/MobileAds#initialize(android.content.Context,com.google.android.gms.ads.initialization.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).

### getInitializationStatus

```
java-static fun getInitializationStatus(): InitializationStatus?
```

Gets the SDK initialization status.

### getRequestConfiguration

```
java-static fun getRequestConfiguration(): RequestConfiguration
```

Gets the global `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/RequestConfiguration`.

### getVersion

```
java-static fun getVersion(): VersionInfo!
```

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

`https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/MobileAds#initialize(android.content.Context)` doesn't need to be called prior to this function.

### initialize

```
@RequiresPermission(value = Manifest.permission.INTERNET)
java-static fun initialize(context: Context!): Unit
```

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: https://developer.android.com/reference/android/content/Context.html!` | The `https://developer.android.com/reference/android/content/Context.html` the SDK is running in. |

### initialize

```
java-static fun initialize(context: Context!, listener: OnInitializationCompleteListener!): Unit
```

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: https://developer.android.com/reference/android/content/Context.html!` | The activity `https://developer.android.com/reference/android/content/Context.html` the SDK is running in. |
| `listener: https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/initialization/OnInitializationCompleteListener!` | A callback to be invoked upon initialization completion. |

### openAdInspector

```
java-static fun openAdInspector(context: Context!, listener: OnAdInspectorClosedListener!): Unit
```

Opens the ad inspector UI.

### openDebugMenu

```
java-static fun openDebugMenu(context: Context!, adUnitId: String!): Unit
```

Opens the debug menu. `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/MobileAds#initialize(android.content.Context)` must be called prior to this function.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html!` | The activity `https://developer.android.com/reference/android/content/Context.html` the SDK is running in. |
| `adUnitId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!` | Any Ad Manager ad unit ID associated with your app. |

### putPublisherFirstPartyIdEnabled

```
java-static fun putPublisherFirstPartyIdEnabled(enabled: Boolean): Boolean
```

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.

`https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/MobileAds#initialize(android.content.Context)` must be called prior to this function.

| Parameters |
|---|---|
| `enabled: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | boolean true if the publisher first-party ID is enabled, false otherwise. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | true if the decision is persisted successfully. False if it fails to be persisted. |

### registerCustomTabsSession

```
java-static fun registerCustomTabsSession(
    context: Context,
    client: CustomTabsClient,
    origin: String,
    callback: CustomTabsCallback?
): CustomTabsSession?
```

Registers a `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsClient.html` with the Google Mobile Ads SDK to improve in-app ad monetization of ads within this `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsSession.html`. This will only create one instance of `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsSession.html` and re-running this overrides the existing session.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | The `https://developer.android.com/reference/android/content/Context.html` the SDK is running in. |
| `client: https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsClient.html` | `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsClient.html` used to create the `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsSession.html` instance. |
| `origin: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | String used as origin on the Digital Asset Link for verification. |
| `callback: https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsCallback.html?` | optional `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsCallback.html` to receive callbacks from `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsSession.html`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsSession.html?` | `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsSession.html` instance to be used for Custom Tabs Intent when opening a Custom Tabs page. |

### registerWebView

```
java-static fun registerWebView(webview: WebView): Unit
```

Registers a `https://developer.android.com/reference/android/webkit/WebView.html` with the Google Mobile Ads SDK to improve in-app ad monetization of ads within this `WebView`.

### setAppMuted

```
java-static fun setAppMuted(muted: Boolean): Unit
```

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: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | true if the app is muted, false otherwise. Defaults to false. |

### setAppVolume

```
java-static fun setAppVolume(volume: Float): Unit
```

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: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html` | the volume as a float from 0 (muted) to 1.0 (full media volume). Defaults to 1.0 |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if volume is out of the valid range |

### setRequestConfiguration

```
java-static fun setRequestConfiguration(requestConfiguration: RequestConfiguration): Unit
```

Sets the global `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/RequestConfiguration` that will be used for every `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/AdRequest` during the app's session.

### startPreload

```
java-static fun [startPreload](https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/MobileAds#startPreload(android.content.Context,java.util.List<com.google.android.gms.ads.preload.PreloadConfiguration>,com.google.android.gms.ads.preload.PreloadCallback))(
    context: Context,
    preloadConfigurations: (Mutable)List<PreloadConfiguration!>,
    preloadCallback: PreloadCallback
): Unit
```

> [!CAUTION]
> **This function is deprecated.**   
>
> Use `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/preload/AdPreloader#start(java.lang.String,com.google.android.gms.ads.preload.PreloadConfiguration,com.google.android.gms.ads.preload.PreloadCallbackV2)` or `https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/preload/AdPreloader#start(java.lang.String,com.google.android.gms.ads.preload.PreloadConfiguration)` 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.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | The `https://developer.android.com/reference/android/content/Context.html` the SDK is running in. |
| `preloadConfigurations: (https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/preload/PreloadConfiguration!>` | The configurations to preload ads. |
| `preloadCallback: https://developers.google.com/admob/android/reference/kotlin/com/google/android/gms/ads/preload/PreloadCallback` | A callback to be invoked when ad availability changes for each preload configuration. |