android - 如何在 Qt Android 应用程序上禁用屏幕保护程序

标签 android c++ qt screensaver

我在 Android 上使用 Qt,我想禁用屏幕关闭/屏幕保护程序打开。

我没有使用 QtQuick/QML,只使用 C++。 Qt版本为5.8

编辑:我忘了提及我使用 Qt Creator。

最佳答案

实际 source

您需要将“QT += androidextras”添加到.pro文件

#include <QtAndroidExtras/QAndroidJniEnvironment>
#include <QtAndroidExtras/QtAndroidExtras>

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<void>("addFlags", "(I)V", FLAG_KEEP_SCREEN_ON);
    }
}

//Clear any possible pending exceptions.
QAndroidJniEnvironment env;
if (env->ExceptionCheck()) {
    env->ExceptionClear();
}

关于android - 如何在 Qt Android 应用程序上禁用屏幕保护程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44100627/

相关文章:

c++ - 如何在 Qt 主线程中正确执行 GUI 操作?

python - Qscrollarea 不显示滚动条并且布局弹出不合适

android - 如何从onCreateViewHolder获取位置

android - 在 android 2.1 中从服务器下载数据

c++ - recursive_invoke_result_t 模板结构

c++ - 检索自上次 n 秒以来设置标志的次数的有效方法

c++ - 我如何抽象出在遗留代码中使用 RogueWave?

android - Dagger- 我们应该为每个 Activity/fragment 创建每个组件和模块吗?

Android ImageView 在 GingerBread 下面的 FrameLayout 中不匹配_parent

c++ - 使用 QNetwork 时的奇怪警告