如何在Android Oreo上振动 [英] How to vibrate on android oreo

查看:139
本文介绍了如何在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));

这篇关于如何在Android Oreo上振动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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