Vibrate setting not turning off on receiving incoming call - Android

只愿长相守 提交于 2019-12-05 20:57:56

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/8065862/vibrate-setting-not-turning-off-on-receiving-incoming-call-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!