android - 已弃用的 AudioManger.setStreamMute 的替代方案?

标签 android android-6.0-marshmallow android-audiomanager

AudioManger.setStreamMute 现在已被 api 23 弃用,最好将 AudioManager.adjustStreamVolumeAudioManager.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/

相关文章:

android - 无法使用 ffmpeg 读取音频流

android - 即使插入耳机,如何通过扬声器播放音频?

java - Android PhoneGap 插件,UI 标签栏,调整 WebView 大小

android - Ionic SQLite——检查数据库是否存在

android - getUidTxBytes(int uid) 在 android 6.0 中总是返回 0

android - onCreate() 在权限设置更改后从最近的任务重新打开时被调用

java - Android只有15个音量位置,如何使用java更精确地调整它?

android - Activity 过渡效果 : slide in for the top activity and scale for the bottom activity

java - 自定义 View 组内的更改未呈现

android - 即使我清除数据并从 6.0.1 设备删除应用程序,Sqlite 数据库仍然存在