我尝试以下列方式读出警报音量,但我总是得到错误的值。铃声音量总是正确!! 这种情况发生在每个智能手机,HTC,三星,索尼甚至虚拟设备上。可能是什么问题?
private AudioManager amanager;
@Override
public void onCreate(Bundle savedInstanceState)
{
amanager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
}
int volume = 3;
int alarm = 3;
try{
volume = amanager.getStreamVolume(amanager.getStreamVolume(AudioManager.STREAM_RING));
alarm = amanager.getStreamVolume(amanager.getStreamVolume(AudioManager.STREAM_ALARM));
Log.i("!!!!!!!!!!", "Activity!!, Volume ringer: " + volume + " Vol Alarm: " + alarm);
}catch(IllegalArgumentException e){}
答案 0 :(得分:1)
我的铃声音量值得错了。方法getStreamVolume (int streamType)
获得int
并返回int
。当你写:
alarm = amanager.getStreamVolume(amanager.getStreamVolume(AudioManager.STREAM_ALARM));
你实际上获得了警报的音量(假设它是X),然后传递给alarm
值alarm = amanager.getStreamVolume(X);
所以结果出乎意料
将volume
和alarm
的值更改为 -
volume = amanager.getStreamVolume(AudioManager.STREAM_RING);
alarm = amanager.getStreamVolume(AudioManager.STREAM_ALARM);