Vibration on QT 6 or newest

92 Views Asked by At

I need call vibration on my Android phone when I clicking on Mouse area, but all guides on old qt 5. In new qt doesn't work, there are QtJNIEnvirinment. I don't know how it write to will vibration. Maybe someone know?

I included Qt =+ core in my .pro file and write this code in cpp file `

#include <QJniObject>
#include <QtAndroid> // not in qt 6

void myAndroidFunction() {

    // Example of using QJniObject to call a Java method
    QJniObject javaString = QJniObject::fromString("Hello from Qt!");
    QJniObject::callStaticMethod<void>(
        "com/example/MyJavaClass", "myJavaMethod", 
        "(Ljava/lang/String;)V", javaString.object<jstring>());

    // Example of accessing an Android API
    QJniObject vibratorService = QtAndroid::androidActivity().callObjectMethod(
        "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;", 
        QJniObject::fromString("vibrator").object<jstring>());

    if (vibratorService.isValid()) {
        vibratorService.callMethod<void>("vibrate", "(J)V", jlong(1000)); // Vibrate for 1 second
    }
}
0

There are 0 best solutions below