# HG changeset patch # User John Tsiombikas # Date 1424058367 -7200 # Node ID 9e3e14ed98eb71e6d3a25fd62675402f1dbd1654 # Parent 64df1dc247359d87d28579afeb6d6092282ff777 android: keep from sleeping while the app is active diff -r 64df1dc24735 -r 9e3e14ed98eb android/AndroidManifest.xml --- a/android/AndroidManifest.xml Mon Jan 26 12:04:33 2015 +0200 +++ b/android/AndroidManifest.xml Mon Feb 16 05:46:07 2015 +0200 @@ -1,5 +1,5 @@ - + diff -r 64df1dc24735 -r 9e3e14ed98eb main.cc --- a/main.cc Mon Jan 26 12:04:33 2015 +0200 +++ b/main.cc Mon Feb 16 05:46:07 2015 +0200 @@ -1,11 +1,37 @@ #include "mainwin.h" #include +static void keep_screen_on(); + int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWin w; w.show(); + keep_screen_on(); + return a.exec(); } + +#ifdef ANDROID +#include +#include + +static void keep_screen_on() +{ + 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); + } + } +} +#else +static void keep_screen_on() +{ +} +#endif diff -r 64df1dc24735 -r 9e3e14ed98eb simple_mtglife.pro --- a/simple_mtglife.pro Mon Jan 26 12:04:33 2015 +0200 +++ b/simple_mtglife.pro Mon Feb 16 05:46:07 2015 +0200 @@ -4,7 +4,8 @@ # #------------------------------------------------- -QT += core gui +QT += core gui +android:QT += androidextras greaterThan(QT_MAJOR_VERSION, 4): QT += widgets