如何在Android Oreo上振动

问题描述:

自3个星期以来,我一直在搜索,而且我会发疯!我已经尝试了在每个论坛上看到的每个代码,但是我无法在android 8.0上的android应用上震动,我已经用cordova制作了一个应用,我试图用(vibrator)(vibrationeffect)做一个插件,我尝试用android studio制作一个空白的本机应用程序,什么也没有.它仅适用于较低版本的Android.

I'm searching since 3 weeks and I'm going crazy! I have try every code I seen on each forum but i'm not able to have vibration on my android app on android 8.0, I have made an app with cordova, i have try to make a plugin with (vibrator) (vibrationeffect) nothing, i have try to make a blank native app with android studio, nothing. It work only on lower version of Android.

振动对于我的应用程序至关重要,我在使用Android 8的2手机上尝试振动,但我遇到了同样的问题,logcat表示一切正常,navigator.vibrate无法正常工作,因为振动无法触摸(这是一个小游戏)

Vibration is essential for my app and I try it on 2 phone with Android 8 and I have the same problem, logcat say everythings ok, navigator.vibrate don't work because vibrate is not on touch (it's a little game).

我需要你的帮助.

1.)初始化振动器类:

1.) Initialize the Vibrator class:

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

2.)叫振动

 vibrator.vibrate(VibrationEffect.createOneShot(30, VibrationEffect.DEFAULT_AMPLITUDE));