Stay organized with collections
Save and categorize content based on your preferences.
The MobileAds class provides global settings for
Next Gen Mobile Ads SDK
.
Video ad volume control
If your app has its own volume controls (such as custom music or sound effect
volumes), disclosing app volume to
Next Gen Mobile Ads SDK
allows video ads to
respect app volume settings. This ensures users receive video ads with the
expected audio volume.
The device volume, controlled through volume buttons or OS-level volume slider,
determines the volume for device audio output. However, apps can independently
adjust volume levels relative to the device volume to tailor the audio
experience. For app open, banner, interstitial, rewarded, and rewarded
interstitial ad formats, you can report the relative app volume to the SDK
through the static setUserControlledAppVolume() method. Valid ad volume values range from
0.0 (silent) to 1.0 (current device volume). Here's an example of how to
report the relative app volume to the SDK:
Kotlin
overridefunonCreate(savedInstanceState:Bundle?){super.onCreate(savedInstanceState)valbackgroundScope=CoroutineScope(Dispatchers.IO)backgroundScope.launch{// Initialize NextGenMobileAdsSDKonabackgroundthread.MobileAds.initialize(this@MainActivity,// Sample Ad Manager app ID: ca-app-pub-3940256099942544~3347511713InitializationConfig.Builder("SAMPLE_APP_ID").build()){}// Set app volume to be half of current device volume.MobileAds.setUserControlledAppVolume(0.5f)}}
Java
@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);newThread(()->{// Initialize NextGenMobileAdsSDKonabackgroundthread.MobileAds.initialize(this,// Sample Ad Manager app ID: ca-app-pub-3940256099942544~3347511713newInitializationConfig.Builder("SAMPLE_APP_ID").build(),initializationStatus->{});// Set app volume to be half of current device volume.MobileAds.setUserControlledAppVolume(0.5f);}).start();}
To inform the SDK that the app volume has muted, use the setUserMutedApp()
method:
Kotlin
MobileAds.setUserMutedApp(true)
Java
MobileAds.setUserMutedApp(true);
By default, the app volume is set to 1 (the current device volume), and the
app is not muted.
Consent for cookies
If your app has special requirements, you can set the optional
SharedPreferencesgad_has_consent_for_cookies. The SDK will enable
limited ads (LTD)
when the gad_has_consent_for_cookies preference is set to zero.
Kotlin
valsharedPrefs=PreferenceManager.getDefaultSharedPreferences(context)// Set the value to 0 to enable limited ads.sharedPrefs.edit().putInt("gad_has_consent_for_cookies",0).apply()
Java
Contextactivity=getActivity();SharedPreferencessharedPreferences=PreferenceManager.getDefaultSharedPreferences(activity);// Set the value to 0 to enable limited ads.sharedPreferences.edit().putInt("gad_has_consent_for_cookies",0).apply();
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-22 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eMobileAds\u003c/code\u003e class provides global settings for the Google Mobile Ads SDK, including video ad volume and consent for cookies.\u003c/p\u003e\n"],["\u003cp\u003eYou can control video ad volume relative to the device volume, ensuring ads respect your app's audio settings, using \u003ccode\u003esetUserControlledAppVolume()\u003c/code\u003e and \u003ccode\u003esetUserMutedApp()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eFor apps with specific requirements, setting the \u003ccode\u003egad_has_consent_for_cookies\u003c/code\u003e SharedPreference to 0 enables limited ads functionality.\u003c/p\u003e\n"]]],["The `MobileAds` class manages Google Mobile Ads SDK settings, including video ad volume and cookie consent. Apps can adjust video ad volume relative to the device volume using `setUserControlledAppVolume()`, with values from 0.0 (silent) to 1.0 (device volume). `setUserMutedApp(true)` indicates app muting. By default, app volume is at 1 and not muted. Apps can enable limited ads by setting the `gad_has_consent_for_cookies` preference to 0 via `SharedPreferences`.\n"],null,["The `MobileAds` class provides global settings for the Google Mobile Ads SDK.\n\nVideo ad volume control\n\nIf your app has its own volume controls (such as custom music or sound effect\nvolumes), disclosing app volume to the Google Mobile Ads SDK allows video ads to\nrespect app volume settings. This ensures users receive video ads with the\nexpected audio volume.\n\nThe device volume, controlled through volume buttons or OS-level volume slider,\ndetermines the volume for device audio output. However, apps can independently\nadjust volume levels relative to the device volume to tailor the audio\nexperience. For app open, banner, interstitial, rewarded, and rewarded\ninterstitial ad formats, you can report the relative app volume to the SDK\nthrough the static `setUserControlledAppVolume()` method. Valid ad volume values range from\n`0.0` (silent) to `1.0` (current device volume). Here's an example of how to\nreport the relative app volume to the SDK: \n\nKotlin \n\n override fun onCreate(savedInstanceState: Bundle?) {\n super.onCreate(savedInstanceState)\n\n val backgroundScope = CoroutineScope(Dispatchers.IO)\n backgroundScope.launch {\n // Initialize the Google Mobile Ads SDK on a background thread.\n MobileAds.initialize(\n this@MainActivity,\n // Sample Ad Manager app ID: ca-app-pub-3940256099942544~3347511713\n InitializationConfig.Builder(\"\u003cvar scope=\"SAMPLE_APP_ID\" translate=\"no\"\u003eSAMPLE_APP_ID\u003c/var\u003e\").build()\n ) {}\n \n // Set app volume to be half of current device volume.\n MobileAds.setUserControlledAppVolume(0.5f)\n }\n }\n\nJava \n\n @Override\n protected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n\n new Thread(\n () -\u003e {\n // Initialize the Google Mobile Ads SDK on a background thread.\n MobileAds.initialize(\n this,\n // Sample Ad Manager app ID: ca-app-pub-3940256099942544~3347511713\n new InitializationConfig.Builder(\"\u003cvar scope=\"SAMPLE_APP_ID\" translate=\"no\"\u003eSAMPLE_APP_ID\u003c/var\u003e\")\n .build(),\n initializationStatus -\u003e {\n });\n \n // Set app volume to be half of current device volume.\n MobileAds.setUserControlledAppVolume(0.5f);\n })\n .start();\n }\n\nTo inform the SDK that the app volume has muted, use the `setUserMutedApp()`\nmethod: \n\nKotlin \n\n MobileAds.setUserMutedApp(true)\n\nJava \n\n MobileAds.setUserMutedApp(true);\n\nBy default, the app volume is set to `1` (the current device volume), and the\napp is not muted.\n| **Note:** Video ads that are ineligible to be shown with muted audio are not returned for ad requests made when the app volume is reported as muted or set to a value of `0`. This may restrict a subset of the broader video ads pool from serving.\n\nConsent for cookies\n\nIf your app has special requirements, you can set the optional\n[`SharedPreferences`](//developer.android.com/reference/android/content/SharedPreferences)\n`gad_has_consent_for_cookies`. The SDK will enable\n\n[limited ads (LTD)](//support.google.com/admanager/answer/9882911)\n\nwhen the `gad_has_consent_for_cookies` preference is set to zero. \n\nKotlin \n\n val sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context)\n // Set the value to 0 to enable limited ads.\n sharedPrefs.edit().putInt(\"gad_has_consent_for_cookies\", 0).apply()\n\nJava \n\n Context activity = getActivity();\n SharedPreferences sharedPreferences =\n PreferenceManager.getDefaultSharedPreferences(activity);\n // Set the value to 0 to enable limited ads.\n sharedPreferences.edit().putInt(\"gad_has_consent_for_cookies\", 0).apply();"]]