只能在Android上更改一个闹钟声音的音量
问题描述:
我正在开发一个救生医疗应用程序,如果用户处于危及生命的情况,他们需要听到警报。只能在Android上更改一个闹钟声音的音量
当我收到状态栏的通知或者有一个对话框出现给用户的重要信息时,我需要引起他们的注意。如果媒体音量或铃声音量低或关闭,我只想为我的警报覆盖它。我不想改变手机的设置,只是为了我想要播放的一个声音。
当我尝试:
AudioManager audioManager = (AudioManager)getSystemService(this.AUDIO_SERVICE);
audioManager.setStreamVolume(AudioManager.STREAM_RING,
audioManager.getStreamMaxVolume(AudioManager.STREAM_RING), 0);
这正确地设置为我流的量,但具有改变其他人的流体积的副作用。
有没有一种方法可以为一首歌曲设置音量?
答
歌曲完成后可以重新设定。
AudioManager audioManager = (AudioManager)getSystemService(this.AUDIO_SERVICE);
int current_volume=audioManager.getStreamVolume(AudioManager.STREAM_RING);
audioManager.setStreamVolume(AudioManager.STREAM_RING,
audioManager.getStreamMaxVolume(AudioManager.STREAM_RING), 0);
// Play here
audioManager.setStreamVolum(AudioManager.STREAM_RING,current_volume,0);