我在 Android 上使用 AIDE,但无法让它振动。
相关代码如下:
import android.os.*;
Vibrator.vibrate((long)1000);
(在 .vibrate 行上)它说“这里没有这样的引用”。当我检查应用程序内的定义时,那里有 Vibrator.vibrate。
这里出了什么问题?它必须是简单的东西,但解决方案不在网络或其他任何地方。
最佳答案
What's wrong here?
vibrate()
不是静态方法。您无法在 Vibrator
类上调用 vibrate()
。您需要在 Vibrator
类的实例上调用vibrate()
。引用the documentation :
To obtain an instance of the system vibrator, call getSystemService(String) with VIBRATOR_SERVICE as the argument.
您还需要在 list 中请求 VIBRATE
权限,并在具有振动电机的设备上运行代码。
关于java - 安卓振动器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24417324/