如何保持在屏幕上的Qt为Android?

如何保持在屏幕上的Qt为Android?

问题描述:

我发现一对夫妇的解决方案如何做到这一点在Java中,却没有发现我怎么能做到这一点的QML Qt的或。我知道,首先我应该设置在的Andr​​oidManifest.xml WAKE_LOCK 许可。我应该怎么做,以使其能够打开和关闭屏幕在运行时从Qt的锁?

I found a couple of solutions how to do that in Java, but did not find how can I do it in QML or Qt. I know that first I should set the WAKE_LOCK permission in AndroidManifest.xml. What should I do to make it possible to turn on and off the screen locking from Qt in runtime?

您可以使用 Qt的额外的Andr​​oid 模块,并使用JNI调用从C ++相关的Java功能。是这样的:

You can use the Qt Android Extras module and use JNI to call the relevant Java function from C++. Something like :

void keepScreenOn() 
{
    QAndroidJniObject activity = QtAndroid::androidActivity();
    if (activity.isValid()) {
        QAndroidJniObject window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;");

        if (window.isValid()) {
            const int FLAG_KEEP_SCREEN_ON = 128;
            window.callObjectMethod("addFlags", "(I)V", FLAG_KEEP_SCREEN_ON);
        }
    }
}