我怎么能知道,如果振动器工作? [英] How can I know if the vibrator is working?

查看:119
本文介绍了我怎么能知道,如果振动器工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有在Android手机震动,所以我可以订阅我的事件处理程序,它被解雇任何情况下?

Is there any event which is fired when the android phone is vibrating so I can subscribe my event handler to it?

感谢您的时间。

推荐答案

您可以使用<一个href=\"http://developer.android.com/reference/android/content/Context.html#getSystemService%28java.lang.String%29\"相对=nofollow> Context.getSystemService()获得振动器对象。使用该对象可以识别手机是否有一个振动器。

You can use Context.getSystemService() to get a Vibrator object. Using that object you can identify whether phone has a vibrator.

Vibrator vibrator  = context.getSystemService(Context.VIBRATOR_SERVICE);

要identfiy手机是否有振动器,使用 hasVibrator ()

to identfiy whether phone has a vibrator, use hasVibrator()

 vibrator.hasVibrator()

您可以开始使用停振

vibrate.vibrate(long milliseconds);
vibrate.cancel();

修改:看到运的评论后..

我不认为当手机开始振动AFAIK你会得到通知。 (快乐,如果有人清除我错了)..你可以找出手机是否处于振动模式或静音模式或正常模式(见<一href=\"http://stackoverflow.com/questions/2048427/how-can-i-detect-whether-the-android-phone-in-silent-mode-programatically\">this)..但振动模式并不意味着现在的手机震动。

After seeing op's comment..

I don't think you will get notification when phone starts vibrating AFAIK. (Happy if someone clears me wrong).. You can find out whether phone is in vibration mode or silent mode or normal mode (See this).. But vibration mode doesn't mean phone is vibrating right now..

这篇关于我怎么能知道,如果振动器工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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