MobileAds クラスは、Google Mobile Ads SDK のグローバル設定を提供します。
動画広告のボリューム調整
アプリに独自の音量調節(音楽や音声効果などのカスタム音量設定)機能が備わっている場合、アプリの音量設定を Google Mobile Ads SDK に開示すれば、動画広告の音量にもアプリ側の音量設定を反映できます。これにより、ユーザーは想定どおりの音量で動画広告を視聴できます。
デバイスのオーディオ出力の大きさは、デバイスの音量(音量ボタンや OS レベルの音量スライダーで制御)で決まりますが、アプリでは、デバイスの音量に対する相対的な音量レベルを独自に調節して、音声の聞こえ方をカスタマイズできます。アプリ起動、バナー、インタースティシャル、リワード、リワード インタースティシャル広告フォーマットの場合は、静的
setAppVolume() メソッドを使用して、相対的なアプリのボリュームを SDK
にレポートすることができます。広告の音量設定値の有効範囲は、0.0(無音)から 1.0(デバイスの現在の音量)までです。アプリ側の相対音量設定を
SDK に伝えるコードは、たとえば次のようになります。
Kotlin
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val backgroundScope = 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
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new Thread(
() -> {
// 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();
}
アプリ側で音声がミュートされたことを SDK に伝えるには、次のように setAppMuted() メソッドを使用します。
Kotlin
MobileAds.setAppMuted(true)
Java
MobileAds.setAppMuted(true);
アプリ側の音量は、デフォルトでは 1(デバイスの現在の音量)に設定されており、アプリはミュートされていない状態です。
ネイティブ広告
ミュート設定を制御する方法については、
VideoOptions
をご覧ください。ネイティブ広告では、カスタムの音量調節はサポートされていません。
Cookie の同意
アプリに特別な要件がある場合は、オプションの
SharedPreferences
gad_has_consent_for_cookiesを設定できます。SDK により
制限付き広告(LTD)
が、gad_has_consent_for_cookies がゼロに設定されている場合に有効にされます。
Kotlin
val sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context)
// Set the value to 0 to enable limited ads.
sharedPrefs.edit().putInt("gad_has_consent_for_cookies", 0).apply()
Java
Context activity = getActivity();
SharedPreferences sharedPreferences =
PreferenceManager.getDefaultSharedPreferences(activity);
// Set the value to 0 to enable limited ads.
sharedPreferences.edit().putInt("gad_has_consent_for_cookies", 0).apply();