How do I prevent an Android device from going to sleep from Qt application

后端 未结 2 1652
故里飘歌
故里飘歌 2021-01-05 17:21

I\'m deploying a Qt application on Android and need to prevent the device from going to standby (else, my threads are interrupted and also my BLE connection gets lost).

2条回答
  •  太阳男子
    2021-01-05 18:05

    Another solution:

    QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");
    if (activity.isValid()) {
        QAndroidJniObject window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;");
        if (window.isValid()) {
            const int FLAG_KEEP_SCREEN_ON = 128;
            window.callMethod("addFlags", "(I)V", FLAG_KEEP_SCREEN_ON);
        }
    }
    

    Source here

    I suggest you to read this question for educational purpose.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题