Turn off web browsing in Android apps

I am creating an application that includes some WebViews.

I want to disable one of them (not all the application or device with this particular one WebView), which I was looking for, but there is no definite answer to this question. Does anyone know how to mute sound WebViewin Android?

+2
source share
1 answer

You cannot only disable the volume of WebViews, but you can disable the entire system volume when you display WebViews. Similar:
When you show that a specific WebView uses the method below:

public static void mute(Context context) {
    AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    int mute_volume = 0;
    mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mute_volume, 0);
}

And when the webView is not displayed, set max volume Like:

public static void unmute(Context context) {
    AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    int unmute_volume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, unmute_volume, 0);
}

,

mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);

Webview.

0

Source: https://habr.com/ru/post/1694052/


All Articles