开发者

android get vibration settings

I need to get the right settings for vibrator so that my application respects the device's sound settings. On the following code, if the vibrator is off(on my phone when I lower the volume, it is a state when the volume is off and vibrator is off and one when volume is off an vibrator is on). When the phone is set to no vibrate (verified by making a call to this device), I still get the vibrator as being on:

AudioManager audioManager = (AudioManager) PingerApplication.getInstance().getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
int vibrationSetting = audioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION);
boolean vibrate;
switch(vibrationSetting) {
case AudioManager.VIBRATE_SETTING_ON:
    vibrate = true;
    break;
case AudioManager.VIBRATE_SETTING_OFF:
开发者_如何学C    vibrate = false;
    break;
case AudioManager.VIBRATE_SETTING_ONLY_SILENT:
    vibrate = (audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE);
    break;
default:
    vibrate = false;
}

Am I doing something wrong? vibrationSetting is always AudioManager.VIBRATE_SETTING_ON


You can also put check on AudioManager.getRingerMode(), e.g.

 AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
    if(audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT)
    {
        // should not vibrate
    }


According to the Javadoc, you should use AudioManager.shouldVibrate(int) instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜