QT笔记- Qt6.8.1 Android编程 手机震动实现
#include "QJniObject"
#include "QJniEnvironment"
// 震动 - 需要手动添加权限'android.permission.VIBRATE'
inline void vibrate(int milliseconds)
{
QJniObject context = QNativeInterface::QAndroidApplication::context();
QJniObject vibrator = context.callObjectMethod("getSystemService",
"(Ljava/lang/String;)Ljava/lang/Object;",
QJniObject::fromString("vibrator").object());
if(vibrator.isValid()){
jlong duration = milliseconds;
vibrator.callMethod<void>("vibrate", "(J)V", duration);
}
}
权限添加参考QT笔记- Qt6.7.1 Android编程 添加AndroidManifest.xml文件以支持修改权限-CSDN博客