views:

218

answers:

2

Hi,

I'm making a vibrate toggling widget (in fact, its first version is already in the Market) but I'm having some problems with the vibrate settings of Android 2.2.

Up to Android 2.1 I have no problem, when I want to disable vibrate 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 but with VIBRATE_SETTING_ON on both lines to turn it on, and it works allright.

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 vibrate is set to "Always" or "Never" there's no problem, but as soon as the user manually sets it to one of the other two settings, the app starts doing strange things.

For example, if I have it set to "vibrate only in silent mode" and I turn vibration off via my widget, it turns off, but when I turn it back on... it goes back to "only in silent mode" instead of "Always". In fact, there's no way to set it back to "Always" unless you do it via Settings -> Sound, so I guess the combobox for vibrate mode is doing something else that I don't know of. It's like it stored the value somewhere else, because even if I set manually to "Always", when I disable it and enable it again via the widget (with the code I posted before) it keeps going back to "Vibrate only in silent mode".

And what's more, there's a value in AudioManager class for "Only in silent mode" (VIBRATE_SETTING_ONLY_SILENT) but when you set it to "Only when not in silent mode" it uses VIBRATE_SETTING_ON, so there are no way to detect it (not that I know of, I mean).

Hope I have not been too confusing, but I wanted to give all the possible data. And with all that set...

Does anyone know how to properly handle vibrate settings in 2.2? Is there any other variable that I have to set or function that I have to call in order to disable or enable vibrate completely? Or a way to "reset" the phone to a known state so that it works ok?

Thank you very much in advance.

The steps to reproduce the problem (or, at least, one of the problems) are:

  • Set vibrate to "only in silent mode" via the settings menu.

  • Set vibrate to "never" via the widget:

    setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);

  • Check in the settings menu that vibrate is set to "never".

  • Set vibrate to "always" via the widget:

    setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON);

  • Go to the settings menu -> Vibrate is set to "Only in silent mode" :S
A: 

I had to mess with these settings myself when some application messed up my Nexus One's individual settings. Here they are:

Always vibrate on ring:

setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON);

Never vibrate on ring:

setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);

Vibrate on ring in silent only:

setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ONLY_SILENT);

Always vibrate on notify:

setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_ON);

Never vibrate on notify:

setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF);

Vibrate on notify in silent only:

setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_ONLY_SILENT);

Change ringer mode:

AudioManager.setRingerMode(RINGER_MODE_NORMAL); AudioManager.setRingerMode(RINGER_MODE_SILENT); AudioManager.setRingerMode(RINGER_MODE_VIBRATE);

Vibrate settings are independent of ringer settings. Confusion ensues.

magaio
Thank you magaio, but I still have the problem... I have added the steps to reproduce the issue in the question.
LuTHieR
LuTHieR, you probably need to use a combination of setting the vibrate setting but also the ringer setting. It's confusing, I know. The Android Settings app is actually changing the ringer setting (see my edit at bottom of answer). If you want a true never-vibrate, you need to setVibrateSetting(... VIBRATE_SETTING_OFF) and setRingerMode(... RINGER_MODE_NORMAL). Give that a try.
magaio
Thank you once again, I'll try it this afternoon when I get home and tell you if it worked :)
LuTHieR
Hi magaio, sorry for the delay. I tried it, but it keeps doing the same :( I tried setting ringer mode to Normal both before and after changing the vibrate settings, but still no luck. Thanks for your time and ideas, though :)
LuTHieR
A: 

Ok, I think I finally fixed it... I looked at the source code of the com.android.settings.Settings class and copied part of the methods that enable and disable vibrate:

http://android.git.kernel.org/?p=platform/packages/apps/Settings.git;a=blob;f=src/com/android/settings/SoundSettings.java;h=a735268b119dda3f91b4f3e987df054eead99f5c;hb=HEAD

Thank you anyway magaio, you pointed me in the right direction ;)

LuTHieR