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 :

    [ANDROID]
    Go to Settings -> Security -> Screen Lock and select NONE

    [iOS]
    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 :

    http://stackoverflow.com/questions/4736354/how-to-enable-or-disable-autolock-in-android



  • 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
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    on QtActivity.java



  • 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 &#40;":/style/styleFile.qss"&#41;;
    if (true == styleFile.open(QFile::ReadOnly&#41;)
    {
        QString style(styleFile.readAll());
        a.setStyleSheet(style);
    }
    
    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.