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博客
原文地址:https://blog.csdn.net/qq_43058397/article/details/145217775
免责声明:本站文章内容转载自网络资源,如侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!