How to prevent device from sleep while application is running

  • 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 :)

  • One solution, if I'm not wrong, is :

    Go to Settings -> Security -> Screen Lock and select NONE

    Go to Settings -> General -> Auto-Lock and select NEVER

    I'm not sure this can be done programatically (probably not using Qt). But (on Android) using Java Native Interface (JNI), it can :

  • 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?

  • You can add

  • peterlin82 : can you tell me where to add? I have no idea where is

    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;;

    QFile styleFile &#40;":/style/styleFile.qss"&#41;;
    if (true ==;)
        QString style(styleFile.readAll());
    return a.exec(&#41;;


    I am using Qt 5.2

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.