simple_mtglife

view main.cc @ 6:9e3e14ed98eb

android: keep from sleeping while the app is active
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 16 Feb 2015 05:46:07 +0200
parents 6321cfa2ad62
children
line source
1 #include "mainwin.h"
2 #include <QApplication>
4 static void keep_screen_on();
6 int main(int argc, char *argv[])
7 {
8 QApplication a(argc, argv);
9 MainWin w;
10 w.show();
12 keep_screen_on();
14 return a.exec();
15 }
17 #ifdef ANDROID
18 #include <QtAndroid>
19 #include <QAndroidJniObject>
21 static void keep_screen_on()
22 {
23 QAndroidJniObject activity = QtAndroid::androidActivity();
24 if(activity.isValid()) {
25 QAndroidJniObject window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;");
27 if(window.isValid()) {
28 const int FLAG_KEEP_SCREEN_ON = 128;
29 window.callObjectMethod("addFlags", "(I)V", FLAG_KEEP_SCREEN_ON);
30 }
31 }
32 }
33 #else
34 static void keep_screen_on()
35 {
36 }
37 #endif