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. Wake up from sleep Android 4.4 Qt

Wake up from sleep Android 4.4 Qt

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
1 Posts 1 Posters 652 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.
  • B Offline
    B Offline
    bijanbina
    wrote on last edited by bijanbina
    #1

    I'm designing an app that should turn off screen if a button pressed and wake the device up if a certain package received on TCP/IP. To acheive this the android device can be rooted and have no lock screen.
    My application GUI is written in qml and the TCP server/client and the corresponding handlers written in QT. The screen turn off work out of the box by using Android device admin
    But I had difficult time to figure out a function for waking up part. I used answer from StackExchange - Turn ON Screen programmatically on Android with no lock
    I can receive the packet while the device is in sleep mode and I can set window flag succefully (for exmple FLAG_FULLSCREEN) but the mentioned solution not wake up my device, despite that I am sure the flag has been set.
    Here is my code:

           QAndroidJniObject javaControl;
           QtAndroid::runOnAndroidThread([&javaControl]()
           {
               int FLAG_SHOW_WHEN_LOCKED = QAndroidJniObject::getStaticField<jint>(
                           "android/view/WindowManager$LayoutParams","FLAG_SHOW_WHEN_LOCKED");
               int FLAG_DISMISS_KEYGUARD = QAndroidJniObject::getStaticField<jint>(
                           "android/view/WindowManager$LayoutParams","FLAG_DISMISS_KEYGUARD");
               int FLAG_KEEP_SCREEN_ON = QAndroidJniObject::getStaticField<jint>(
                           "android/view/WindowManager$LayoutParams","FLAG_KEEP_SCREEN_ON");
               int FLAG_TURN_SCREEN_ON = QAndroidJniObject::getStaticField<jint>(
                           "android/view/WindowManager$LayoutParams","FLAG_TURN_SCREEN_ON");
               int FLAG_ALLOW_LOCK_WHILE_SCREEN_ON = QAndroidJniObject::getStaticField<jint>(
                           "android/view/WindowManager$LayoutParams","FLAG_ALLOW_LOCK_WHILE_SCREEN_ON");
               qDebug() << "MI6 Hello:" << (FLAG_SHOW_WHEN_LOCKED |
                           FLAG_DISMISS_KEYGUARD | FLAG_KEEP_SCREEN_ON |
                           FLAG_TURN_SCREEN_ON | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
    
               QAndroidJniObject activity = QtAndroid::androidActivity();
               QAndroidJniObject a_window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;");
               a_window.callMethod<void>("addFlags", "(I)V", FLAG_SHOW_WHEN_LOCKED |
                                       FLAG_DISMISS_KEYGUARD | FLAG_KEEP_SCREEN_ON |
                                       FLAG_TURN_SCREEN_ON | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
           });
    

    I ran the code in main thread because it is the only way to set a window flag

    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