AudioManger.setStreamMute 现在已被 api 23 弃用,最好将 AudioManager.adjustStreamVolume
与 AudioManager.ADJUST_MUTE 一起使用。
我的问题是只有 api 23 支持这种标志,而我的应用程序至少是 api 16。
是否有其他方法可以使整个系统静音?
如果不是,为什么谷歌会弃用这种方法?
最佳答案
我的做法是使用 if/else block 来根据应用程序当前运行的 Android 版本使用正确的调用。
// Change the stream to your stream of choice.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
am.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_MUTE, 0);
} else {
am.setStreamMute(AudioManager.STREAM_MUSIC, true);
}
关于android - 已弃用的 AudioManger.setStreamMute 的替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33057428/