I am making a vibrating toggle widget (in fact, its first version is already on the market), but I am having some problems with the settings for Android 2.2 vibration call.
Prior to Android 2.1, I have no problem when I want to turn off vibration, I do
am.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,AudioManager.VIBRATE_SETTING_OFF); am.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION,AudioManager.VIBRATE_SETTING_OFF);
and the same thing, but with VIBRATE_SETTING_ON on both lines to turn it on, and it works fine.
However, since Android 2.2 introduced "Vibrate only in silent mode" and "Vibrate when not in silent mode", I don’t know how to make it work. When the vibration alert is set to Always or Never, there is no problem, but as soon as the user manually sets it to one of the other two settings, the application starts doing strange things.
For example, if I have it set to "vibration only in silent mode" and I turn off vibration through my widget, it will turn off, but when I return it back ... it will return to "only in silence" mode "instead of" Always " Actually, there is no way to return it to "Always" if you do not do it using "Settings" -> "Sound", so I think the combo box for the vibrating alert does something else that I'm not talking about I know. It seems to be storing the value somewhere else, because even if I manually set "Always" when I turn it off and on again through the widget (with previously published code), he continues to return to "Vibrate in silent mode only."
And what’s more, there is a value in the AudioManager class for “Only in silent mode” (VIBRATE_SETTING_ONLY_SILENT), but when you set it to “Only when it is not in quiet mode”, it uses VIBRATE_SETTING_ON, so there is no way to detect it (not that, what I know, I mean).
I hope I was not too confused, but I wanted to give all the possible data. And with all this set ...
Does anyone know how to properly handle vibration settings in 2.2? Is there any other variable that I have to set or a function that I have to call to completely disable or enable vibration? Or is there a way to "reset" the phone to a known state so that it works fine?
Actions to reproduce the problem (or at least one of the problems):
Set the settings in "silent mode only" mode in the settings menu.
Set the widget to "never" through the widget:
setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
Check the settings menu, in which the vibration alert is set to "never".
Set the widget to "always" through the widget:
setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON);
- Go to the settings menu → Vibrate is set to "Only in silent mode"