המחלקות MobileAds מספקות הגדרות גלובליות ל-Google Mobile Ads SDK.
שליטה בעוצמת הקול של מודעות וידאו
אם לאפליקציה יש פקדי עוצמת קול משלה (כמו לחצנים מותאמים אישית לשליטה בעוצמת הקול של המוזיקה או האפקטים), חשיפת עוצמת הקול של האפליקציה ל-Google Mobile Ads SDK מאפשרת למודעות וידאו לפעול בהתאם להגדרות עוצמת הקול של האפליקציה. כך המשתמשים יקבלו מודעות וידאו עם עוצמת הקול הצפויה.
עוצמת הקול של המכשיר, שנשלטת באמצעות לחצני עוצמת הקול או פס עוצמת הקול ברמת מערכת ההפעלה, קובעת את עוצמת הקול של פלט האודיו של המכשיר. עם זאת, אפליקציות יכולות לשנות את עוצמת הקול באופן עצמאי ביחס לעוצמת הקול של המכשיר, כדי להתאים את חוויית האודיו. בפורמטים של מודעות בפתיחת האפליקציה, מודעות באנר, מודעות מעברון, מודעות מתגמלות ומודעות מעברון מתגמלות, אפשר לדווח ל-SDK על עוצמת הקול היחסית של האפליקציה באמצעות השיטה הסטטית setAppVolume(). הערכים התקינים של עוצמת הקול של המודעה נעים בין 0.0 (ללא קול) לבין 1.0 (עוצמת הקול הנוכחית של המכשיר). דוגמה לאופן הדיווח על נפח האפליקציות היחסי ל-SDK:
Kotlin
overridefunonCreate(savedInstanceState:Bundle?){super.onCreate(savedInstanceState)valbackgroundScope=CoroutineScope(Dispatchers.IO)backgroundScope.launch{// Initialize Google Mobile Ads SDK on a background thread.MobileAds.initialize(this@MainActivity){}// Set app volume to be half of current device volume.MobileAds.setAppVolume(0.5f)}}
Java
@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);newThread(()->{// Initialize Google Mobile Ads SDK on a background thread.MobileAds.initialize(this,initializationStatus->{});// Set app volume to be half of current device volume.MobileAds.setAppVolume(0.5f);}).start();}
setAppMuted()
כדי להודיע ל-SDK שעוצמת הקול של האפליקציה הושתקה, משתמשים בשיטה:
Kotlin
MobileAds.setAppMuted(true)
Java
MobileAds.setAppMuted(true);
כברירת מחדל, עוצמת הקול של האפליקציה מוגדרת ל1 (עוצמת הקול הנוכחית במכשיר), והאפליקציה לא מושתקת.
מודעות מותאמות
הוראות להגדרת השתקה מופיעות במאמר בנושא VideoOptions. אין תמיכה בבקרת עוצמת קול בהתאמה אישית במודעות מובנות.
הסכמה לשימוש בקובצי Cookie
אם לאפליקציה שלכם יש דרישות מיוחדות, אתם יכולים להגדיר את האפשרות SharedPreferencesgad_has_consent_for_cookies. SDK יפעיל מודעות מוגבלות (LTD) כשההעדפה gad_has_consent_for_cookies מוגדרת לאפס.
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();
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-09-05 (שעון 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 by setting the app volume relative to the device volume using \u003ccode\u003eMobileAds.setAppVolume()\u003c/code\u003e and muting with \u003ccode\u003eMobileAds.setAppMuted()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eIf your app has special requirements for cookies, you can enable limited ads by setting the \u003ccode\u003egad_has_consent_for_cookies\u003c/code\u003e SharedPreference to 0.\u003c/p\u003e\n"],["\u003cp\u003eNative ads have separate video options and do not support custom volume control.\u003c/p\u003e\n"]]],["The `MobileAds` class manages the Google Mobile Ads SDK settings. Apps can adjust video ad volume by using `setAppVolume()`, with values from 0.0 (silent) to 1.0 (device volume), ensuring video ads respect app volume. `setAppMuted()` mutes the app volume. For limited ads (LTD), setting the `gad_has_consent_for_cookies` preference to 0 enables them. The SDK default volume is 1, and the app is not muted initially. Native ads have distinct volume controls, via `VideoOptions`.\n"],null,["Select platform: [Android](/admob/android/global-settings \"View this page for the Android platform docs.\") [iOS](/admob/ios/global-settings \"View this page for the iOS platform docs.\") [Unity](/admob/unity/global-settings \"View this page for the Unity platform docs.\")\n\n\u003cbr /\u003e\n\nThe `MobileAds` class provides global settings for 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 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 `setAppVolume()` 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 Google Mobile Ads SDK on a background thread.\n MobileAds.initialize(this@MainActivity) {}\n \n // Set app volume to be half of current device volume.\n MobileAds.setAppVolume(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 Google Mobile Ads SDK on a background thread.\n MobileAds.initialize(this, initializationStatus -\u003e {});\n \n // Set app volume to be half of current device volume.\n MobileAds.setAppVolume(0.5f);\n })\n .start();\n }\n\nTo inform the SDK that the app volume has muted, use the `setAppMuted()`\nmethod: \n\nKotlin \n\n MobileAds.setAppMuted(true)\n\nJava \n\n MobileAds.setAppMuted(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\nNative ads\n\nSee\n[`VideoOptions`](/admob/android/native/video-ads#videooptions)\nfor instructions on how to control the mute settings. Custom volume control is\nnot supported for native ads.\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/admob/answer/10105530)\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();"]]