in Some cases in your app you just wanna the phone to vibrate if a certain button in your app has been clicked , in my case there is a search mode that switching to and from this mode will make the phone vibrate and also this would happen if the "back" key is pressed , and if the user has enabled the vibrate for software keys in setting then there will be 2 quick vibrates and its not cool , I was wondering if there is any way to detect this cause I cant simply disable it cause in some phones it may be disabled or the key is software so there wont be any vibrate at all thanks
在你的应用程序的某些情况下,如果你的应用程序中的某个按钮被点击,你只想手机振动,在我的情况下有一个搜索模式,切换到这种模式将使手机振动,如果这种情况发生,如果按下“后退”键,如果用户在设置中启用了软键的振动,那么将有2个快速振动并且它不酷,我想知道是否有任何方法来检测这个原因我不能简单地禁用它在一些手机中它可能被禁用或键是软件所以不会有任何振动感谢
2 个解决方案
#1
1
Unfortunately there is no listener for event handling vibrations. see this question
不幸的是,事件处理振动没有听众。看到这个问题
you cant help with it even accelerometer or shake listener. It would be too weak to detect. See documentation if it helps.
你无法帮助它甚至加速度计或摇动听众。检测起来太弱了。如果有帮助,请参阅文档。
#2
-1
Use bellow code for vibration :
使用波纹管代码进行振动:
Vibrator v1 = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
v1.vibrate(500);
Add permission in android manifest :
在android清单中添加权限:
<uses-permission android:name="android.permission.VIBRATE"/>
#1
1
Unfortunately there is no listener for event handling vibrations. see this question
不幸的是,事件处理振动没有听众。看到这个问题
you cant help with it even accelerometer or shake listener. It would be too weak to detect. See documentation if it helps.
你无法帮助它甚至加速度计或摇动听众。检测起来太弱了。如果有帮助,请参阅文档。
#2
-1
Use bellow code for vibration :
使用波纹管代码进行振动:
Vibrator v1 = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
v1.vibrate(500);
Add permission in android manifest :
在android清单中添加权限:
<uses-permission android:name="android.permission.VIBRATE"/>