Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to prevent device from sleep while application is running
QtWS25 Last Chance

How to prevent device from sleep while application is running

Scheduled Pinned Locked Moved Mobile and Embedded
5 Posts 3 Posters 5.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Abin
    wrote on 16 Apr 2014, 13:40 last edited by
    #1

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

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cezmen
      wrote on 16 Apr 2014, 17:07 last edited by
      #2

      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

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Abin
        wrote on 17 Apr 2014, 05:52 last edited by
        #3

        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?

        1 Reply Last reply
        0
        • P Offline
          P Offline
          peterlin82
          wrote on 17 Apr 2014, 08:12 last edited by
          #4

          You can add
          getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
          on QtActivity.java

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Abin
            wrote on 20 Apr 2014, 05:45 last edited by
            #5

            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

            1 Reply Last reply
            0

            3/5

            17 Apr 2014, 05:52

            • Login

            • Login or register to search.
            3 out of 5
            • First post
              3/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved