How to prevent device from sleep while application is running
-
wrote on 16 Apr 2014, 13:40 last edited by
Hi,
I have an android application to show slideshow. The device after some time, gets the screen dim, and goes off and locked. How can I avoid this, until user quits the application.
Like similar to "android.permission.WAKE_LOCK" and call some functions.. I'm not sure exactly.
Thanks in advance :)
-
wrote on 16 Apr 2014, 17:07 last edited by
One solution, if I'm not wrong, is :
[ANDROID]
Go to Settings -> Security -> Screen Lock and select NONE[iOS]
Go to Settings -> General -> Auto-Lock and select NEVERI'm not sure this can be done programatically (probably not using Qt). But (on Android) using Java Native Interface (JNI), it can :
http://stackoverflow.com/questions/4736354/how-to-enable-or-disable-autolock-in-android
-
wrote on 17 Apr 2014, 05:52 last edited by
Thanks for the reply.
Screen Lock - > select NONE will only just doesn't lock the device, but the screen will dim and turns off after the set timeout in setting->Display->Dimmer and Settings->Display->Sleep. These settings doesn't have a NONE option. :(
So from Qt there is no way to acquire this?
-
wrote on 17 Apr 2014, 08:12 last edited by
You can add
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
on QtActivity.java -
wrote on 20 Apr 2014, 05:45 last edited by
peterlin82 : can you tell me where to add? I have no idea where is QtActivity.java
My application code is just same like desktop application:
@#include "pricechecker.h"
#include <QApplication>int main(int argc, char *argv[])
{
QApplication a(argc, argv);
PriceChecker w;
w.show();QFile styleFile (":/style/styleFile.qss"); if (true == styleFile.open(QFile::ReadOnly)) { QString style(styleFile.readAll()); a.setStyleSheet(style); } return a.exec();
}
@I am using Qt 5.2
4/5