android 手机振动不会停止使用取消方法
我编写了一些代码,可以在收到来电时将手机静音。 当手机处于振动模式时,我使用以下代码来停止手机振动:
Vibrator vib = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
vib.cancel();
虽然它在装有 android 2.1 的 Nexus One 上运行,但似乎无法在装有 android 2.1 的 HTC Desire 手机上停止振动。 有人遇到过这个问题吗?
多伦
I wrote some code that mute the phone whenever an incoming call is received.
When the phone in vibrate mode I use the following code to stop the phone vibration:
Vibrator vib = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
vib.cancel();
While it worked on my Nexus One with android 2.1, it seems that it doesn't stop the vibration on an HTC Desire handset with android 2.1.
Have someone encountered this issue?
Doron
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是 Android 的缺点之一,不同的设备表现不同。您是否尝试过使用
vibrate(3000);
这相当于让设备振动 3 秒,而不是尝试取消已启动的服务?That's one of the cons with Android, different devices behave differently. Have you tried using
vibrate(3000);
which is equivalent to let the device vibrate for 3 seconds, insted of trying to cancel a started service?似乎振动没有停止,因为附加到来电广播接收器的停止振动代码在某些情况下在振动开始之前被执行,因此振动看起来没有停止。
我的解决方案是检查手机是否振动,如果是,则关闭振动,否则将振动模式设置关闭,以防止振动开始。
It seems that the vibration doesn’t stop since the stop vibration code which is attached to an incoming call broadcast receiver is executed in some cases before the vibration start and therefore it seems that the vibration doesn't stop.
The solution for me was to check whether the phone vibrates and if so to turn the vibration off else to turn the vibration mode setting to off which prevent the vibration to start.