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
Forum Updated to NodeBB v4.3 + New Features

How to prevent device from sleep while application is running

Scheduled Pinned Locked Moved Mobile and Embedded
5 Posts 3 Posters 6.0k Views 1 Watching
  • 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 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 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 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 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 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

            • Login

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