mirror of
https://gitlab.com/eql/lqml.git
synced 2025-12-05 18:20:33 -08:00
23 lines
703 B
C++
23 lines
703 B
C++
#include "qt.h"
|
|
#include <QtAndroid>
|
|
#include <QAndroidJniEnvironment>
|
|
|
|
QVariant QT::keepScreenOn(const QVariant& on) {
|
|
QtAndroid::runOnAndroidThread([&] {
|
|
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;
|
|
const char* method = on.toBool() ? "addFlags" : "clearFlags";
|
|
window.callMethod<void>(method, "(I)V", FLAG_KEEP_SCREEN_ON);
|
|
}
|
|
}
|
|
QAndroidJniEnvironment env;
|
|
if (env->ExceptionCheck()) {
|
|
env->ExceptionClear();
|
|
}
|
|
});
|
|
return on;
|
|
}
|
|
|