2

我需要为振动器设置正确的设置,以便我的应用程序尊重设备的声音设置。在下面的代码中,如果振动器关闭(在我的手机上,当我降低音量时,它是音量关闭且振动器关闭的状态,以及音量关闭时振动器打开的状态)。当手机设置为无振动(通过拨打此设备进行验证)时,我仍然让振动器处于打开状态:

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:
    vibrate = false;
    break;
case AudioManager.VIBRATE_SETTING_ONLY_SILENT:
    vibrate = (audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE);
    break;
default:
    vibrate = false;
}

难道我做错了什么?振动设置始终AudioManager.VIBRATE_SETTING_ON

4

2 回答 2

2

您还可以检查 AudioManager.getRingerMode(),例如

 AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
    if(audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT)
    {
        // should not vibrate
    }
于 2012-12-24T09:58:34.403 回答
0

根据 Javadoc,您应该AudioManager.shouldVibrate(int)改用。

于 2011-09-27T14:35:48.487 回答