振动设置不接收来电关闭 - 机器人 [英] Vibrate setting not turning off on receiving incoming call - Android

查看:218
本文介绍了振动设置不接收来电关闭 - 机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要关闭设备振动设置当电话打进来。我已经实现一个BroadcastReceiver此功能,在执行接收 PHONE_STATE 播出的行动。问题是,我不能够关闭震动的。我已经试过如下:

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);

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.

有没有人试过这种?

编辑:我查了一下Android的手机应用程序code。继code是present中的 Ringer.java

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.

推荐答案

这样的:

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.

这篇关于振动设置不接收来电关闭 - 机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆