如何针对特定来电提供定制振动
该程序的功能如下:用户有一个电话号码列表,只有当没有其他系统范围的应用程序提供振动(例如在静音模式下)时,手机才会在来电时振动。我知道这在某种程度上违反了规则,因为应用程序应该尊重用户的设置,但应用程序仅限于某些有此需求的用户。我尝试了两种方法,但都不满意:
监听电话状态并用我自己的模式直接触发振动服务(使用
Vibrator.vibrate()
)。此方法在没有来电的情况下有效,但在手机处于CALL_STATE_RINGING
状态时随机有效,我猜这是因为与实际处理来电振动的系统范围应用程序发生冲突。判断手机来电时是否振动(使用
AudioManager.shouldVibrate()
),并决定是否更改振动设置(使用AudioManager.setRingerMode()
> 和AudioManager.setVibrateSetting()
)。如果我的应用程序更改了振动设置,则一旦手机返回到CALL_STATE_IDLE
状态,这些设置就会恢复。但这个方法有时还是不行,没有任何原因。
我希望有人可以就这个问题提供一些建议。欢迎对这两种方式发表评论或其他建议。
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:
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 inCALL_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.Judge whether the cellphone is vibrating upon an incoming call (with
AudioManager.shouldVibrate()
), and decide whether to change the vibrate settings (withAudioManager.setRingerMode()
andAudioManager.setVibrateSetting()
). If the vibrate settings are changed by my application, they are to be restored once the cellphone is back toCALL_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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用两种设置才能使手机振动。第一个是需要使用 AufioManager 设置的声音模式:
第二部分没有正确记录,我相信这是代码中缺少的部分:
使用 1 打开振动,使用 0 关闭振动。
要完全了解如何使用振动设置和模式,请查看以下链接:
http://hi-android.info/src/com/android /settings/SoundSettings.java.html
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:
The second part is not properly documented and I believe this is the missing part of your code:
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