22

The program functions like this: the user has a list of phone numbers, for which the cellphone could vibrate upon an incoming call only when no other system-wide application would provide vibration (such as in mute mode). I know that this is somehow against the rules, for that an application should respect the users' settings, but the application is limited to some certain users with this need. I have tried two ways but neither of them are satisfying:

  1. Listen to the telephony state and directly trigger the vibration service with my own pattern (with Vibrator.vibrate()). This method is effective with no incoming calls yet randomly effective when the phone is in CALL_STATE_RINGING state and I guess it's because of the conflict with the system-wide application that actually handles the vibration upon incoming call.

  2. Judge whether the cellphone is vibrating upon an incoming call (with AudioManager.shouldVibrate()), and decide whether to change the vibrate settings (with AudioManager.setRingerMode() and AudioManager.setVibrateSetting()). If the vibrate settings are changed by my application, they are to be restored once the cellphone is back to CALL_STATE_IDLE state. This method, however, is still not functioning sometimes, without any sign of the reason.

I hope that someone could give some advice on this issue. Comments on these two ways or other suggest are welcome.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
peter
  • 1,034
  • 1
  • 9
  • 23
  • 2
    @Rizon Sadly no, and this question earns me a tumbleweed badge. – peter Mar 14 '12 at 01:30
  • This is not the same but someone tryed disabling vibration on incomming calls and it proved impossible, but the findings are interesting to you: http://stackoverflow.com/q/8065862/969325 – Warpzit Apr 28 '12 at 18:59
  • @Warpzit Thanks. It seems if I could receive the broadcast before Ringer do, the problem is solved. I am not sure how to do that, maybe I should check Ringer.java out. – peter Apr 29 '12 at 01:48
  • `setVibrateSetting()` with `setRingerMode()` seems to work on my phone. Could you post your code? – Sergey Glotov May 05 '12 at 14:04
  • @SergeyGlotov Well, actually they work for my phone as well. The problem appears on my friend's device being tested. I am just looking for some more robust way. Code is too long and complicated, and I am afraid it's not where the problem lies. – peter May 05 '12 at 16:47
  • Hello Peter. I have having same issue. Can you please help me? Please provide some code. – Hardik Joshi Nov 07 '14 at 15:22

1 Answers1

6

You need to play with two settings in order for your phone to vibrate. The first one is the sound mode which needs to be set by using AufioManager:

AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
audioManager.setRingerMode(targetSoundMode);

The second part is not properly documented and I believe this is the missing part of your code:

String VIBRATE_IN_SILENT_SETTING_NAME = "vibrate_in_silent";
Settings.System.putInt(getContentResolver(), VIBRATE_IN_SILENT_SETTING_NAME, 1);

use 1 to turn vibrate on and 0 to turn vibrate off.

to fully understand how you should work with vibrate settings and mode take a look at the following link: http://hi-android.info/src/com/android/settings/SoundSettings.java.html

Muzikant
  • 8,070
  • 5
  • 54
  • 88
  • Thanks for your answer! But this is not what blocks the vibrator, because `vibrate_in_silent` is already set to 1. Is it possible that Phone.apk cancels the Vibrator immediately after we trigger it? According to [VibratorService.java](http://androidxref.com/source/xref/frameworks/base/services/java/com/android/server/VibratorService.java), the Vibrator would behave randomly in this situation. And this explains why the problem only occurs on some cellphones: Phone.apk is not part of the System. – peter May 09 '12 at 15:10
  • 2
    Have you looked at the setPhoneVibrateSettingValue function on the link above ? There is some dependency between these two settings that should be handled very carefully – Muzikant May 10 '12 at 12:38
  • The dependency is something I've missed. I am going to perform some tests on more devices for the dependency. Thanks in advance! +1 to you. – peter May 11 '12 at 02:25
  • Link is dead. I am having same issue. Can you help me ? – Hardik Joshi Nov 07 '14 at 15:26
  • @Prince Hi, you can view [SoundSettings.java](http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-apps/5.L_preview/com/android/settings/SoundSettings.java) in the latest release code. – peter Nov 08 '14 at 03:15
  • @peter Okey let me check it. Just to know is it possible to set level of vibration at incoming call ? I have asked question : http://stackoverflow.com/questions/26804939/how-to-change-incoming-call-vibration-level-when-incoming-call-made – Hardik Joshi Nov 08 '14 at 16:57
  • @Prince I don't think so as I have never seen docs related to level. – peter Nov 11 '14 at 01:38
  • @peter :( Okey friend. My bad luck. – Hardik Joshi Nov 11 '14 at 14:31