8

I want to turn off device vibrate setting when a call comes. I have implemented a BroadcastReceiver for this feature which performs the action on receiving PHONE_STATE broadcast. The problem is that I am not able to turn off vibrations at all. I have tried the following:

AudioManager audioManager = (AudioManager)
                            context.getSystemService(Context.AUDIO_SERVICE);
audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, 
                               AudioManager.VIBRATE_SETTING_OFF);

or

Vibrator vib = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
vib.cancel();

The first approach seems ideal to me. It even works for turning "on" the vibrations when a call is received. But, I am not able turn them "off" in this scenario.

Has anybody tried this?

Edit: I checked Android's Phone app code. Following code is present in Ringer.java:

if (shouldVibrate() && mVibratorThread == null) {
    mContinueVibrating = true;
    mVibratorThread = new VibratorThread();
    mVibratorThread.start();
}

A thread is started initially by Phone app which vibrates the phone. When I change the vibrate setting to off this check is skipped but the already started thread keeps on running.

This also explains how vibrations can be turned on when an incoming call comes. In that case, the thread is not running initially. Then, it is started when I turn on the vibrate setting. I don't think there is any solution to the problem without changing the Phone app.

Tim
  • 6,692
  • 2
  • 25
  • 30
Aman Bakshi
  • 231
  • 3
  • 6
  • 1
    i would be interested in that too. as far as i know it's like that: the thread or context that starts the vibration is the only one that can stop it later. about changing the vibration settings: there seems to be a bug in android. no notification is sent to listeners if the setting changes, therefore the vibration can not stop. – SimonSays Jun 08 '12 at 23:19
  • Hello Aman, Did you resolved this issue? I am facing same issue, hope you will help me regarding same. – Hardik Joshi Oct 29 '14 at 17:40

1 Answers1

0

this:

Vibrator vib = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
vib.cancel();

is not going to help you as it cancels the new instance of the Vibrator.

I can imagine that it's too late to turn of the vibration of the device if the call is already incoming as the vibration is already in progress. So you'd have to do that before the call comes in.

Tim
  • 6,692
  • 2
  • 25
  • 30
  • I want to change the vibrate setting only if incoming call is from one of the selected contacts. So, changing the vibrate setting before incoming call, is not an option. Since Android allows ringer mode and ringer volume to be changed after call comes in, I was hoping to change vibrate as well. – Aman Bakshi Jun 15 '12 at 18:51