Publish the new topic about: "How to Vibrate the device" at following link
List below steps for all developers.
0) change the .pro file in QT in this way:
- QT += core gui androidextras
- ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
1) Add the permission in the AndroidMainifest.xml
- <uses-permission android:name="android.permission.VIBRATE"/>
2) replace the attribute in the activity:
from
- android:name="org.qtproject.qt5.android.bindings.QtActivity"
to
- android:name="org.qtproject.example.Chronometer.Vibrate"
Where Chronometer and Vibrate string can be changes.
3) add the include following in the mainwindow.h
- #include <QtAndroidExtras/QAndroidJniObject>
4) add the following Vibrate.java class in the following directory
myprogget>android/src/org/qtproject/example/Chronometer/
where Chronometer can be change:
- //
- // Vibrate.java
- //
- package org.qtproject.example.Chronometer;
- import android.content.Context;
- import android.os.Vibrator;
- import android.app.Activity;
- import android.os.Bundle;
- public class Vibrate extends org.qtproject.qt5.android.bindings.QtActivity
- {
- public static Vibrator m_vibrator;
- public static Vibrate m_istance;
- public Vibrate()
- {
- m_istance = this;
- }
- public static void start(int x)
- {
- if (m_vibrator == null)
- {
- if (m_istance != null)
- {
- m_vibrator = (Vibrator) m_istance.getSystemService(Context.VIBRATOR_SERVICE);
- m_vibrator.vibrate(x);
- }
- }
- else m_vibrator.vibrate(x);
- }
- }
5) in your program call class in this way:
- QAndroidJniObject::callStaticMethod<void>("org/qtproject/example/Chronometer/Vibrate", "start", "(I)V", 300);