mirror of
https://gitlab.com/eql/lqml.git
synced 2025-12-07 02:51:09 -08:00
example 'meshtastic': add 'qt:keep-screen-on' for mobile
This commit is contained in:
parent
2dfb82b5d3
commit
8640a5760b
6 changed files with 49 additions and 0 deletions
26
examples/meshtastic/cpp/android.cpp
Normal file
26
examples/meshtastic/cpp/android.cpp
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#include "qt.h"
|
||||
#include <QtAndroid>
|
||||
#include <QAndroidJniEnvironment>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
Loading…
Add table
Add a link
Reference in a new issue