当 Android 手机振动时是否会触发任何事件,以便我可以订阅我的事件处理程序?
感谢您的时间。
您可以使用Context.getSystemService() http://developer.android.com/reference/android/content/Context.html#getSystemService%28java.lang.String%29得到一个Vibrator http://developer.android.com/reference/android/os/Vibrator.html目的。使用该对象您可以识别手机是否有振动器。
Vibrator vibrator = context.getSystemService(Context.VIBRATOR_SERVICE);
要识别手机是否有振动器,请使用有振动器() http://developer.android.com/reference/android/os/Vibrator.html#hasVibrator%28%29
vibrator.hasVibrator()
您可以使用以下命令启动和停止振动
vibrate.vibrate(long milliseconds);
vibrate.cancel();
编辑:看到op的评论后..
我认为当手机开始振动时您不会收到通知。 (如果有人澄清我的错误,我会很高兴)..您可以了解手机是否处于振动模式、静音模式或正常模式(请参阅this https://stackoverflow.com/questions/2048427/how-can-i-detect-whether-the-android-phone-in-silent-mode-programatically)..但是振动模式并不意味着手机现在正在振动..
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)