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. FLAG_KEEP_SCREEN_ON and Android 30

FLAG_KEEP_SCREEN_ON and Android 30

Scheduled Pinned Locked Moved Solved Mobile and Embedded
4 Posts 2 Posters 1.5k 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.
  • mrdebugM Offline
    mrdebugM Offline
    mrdebug
    wrote on last edited by
    #1

    Hi, I'm using these lines of code

        #ifdef Q_OS_ANDROID
            QAndroidJniObject activity= QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");
            if (activity.isValid()) {
                QAndroidJniObject window= activity.callObjectMethod("getWindow", "()Landroid/view/Window;");
                if (window.isValid()) {
                    const int FLAG_KEEP_SCREEN_ON= 128;
                    window.callMethod<void>("addFlags", "(I)V", FLAG_KEEP_SCREEN_ON);
                }
            }
            QAndroidJniEnvironment env;
            if (env->ExceptionCheck()) env->ExceptionClear();
        #endif
    

    to keep the screen on. This approach works on an Android 6 device but not on an Android 11 device.
    Does someone have a suggestion for me in order to resolve?

    Need programmers to hire?
    www.labcsp.com
    www.denisgottardello.it
    GMT+1
    Skype: mrdebug

    1 Reply Last reply
    0
    • mrdebugM Offline
      mrdebugM Offline
      mrdebug
      wrote on last edited by
      #2

      Solved following
      https://forum.qt.io/topic/57625/solved-keep-android-5-screen-on

      Need programmers to hire?
      www.labcsp.com
      www.denisgottardello.it
      GMT+1
      Skype: mrdebug

      1 Reply Last reply
      1
      • R Offline
        R Offline
        rdowell
        wrote on last edited by rdowell
        #3

        @mrdebug said in FLAG_KEEP_SCREEN_ON and Android 30:

            QAndroidJniObject activity= QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");
            if (activity.isValid()) {
                QAndroidJniObject window= activity.callObjectMethod("getWindow", "()Landroid/view/Window;");
                if (window.isValid()) {
                    const int FLAG_KEEP_SCREEN_ON= 128;
                    window.callMethod<void>("addFlags", "(I)V", FLAG_KEEP_SCREEN_ON);
                }
            }
            QAndroidJniEnvironment env;
            if (env->ExceptionCheck()) env->ExceptionClear();
        

        @mrdebug said in FLAG_KEEP_SCREEN_ON and Android 30:

        Solved following
        https://forum.qt.io/topic/57625/solved-keep-android-5-screen-on

        What method did you solve this with from that linked issue? I tried the same code as you have here and it seems to work fine on Android 9, however we may be updating to 10/11 at some point. Did you use the method of extending the Qt Java activity and find that works on Android 11?

        1 Reply Last reply
        0
        • mrdebugM Offline
          mrdebugM Offline
          mrdebug
          wrote on last edited by
          #4

          This approach works on Android 6 and 11

          package it.denisgottardello.metronome.metronometouch;
          
          public class MetronomeTouchMain extends org.qtproject.qt5.android.bindings.QtActivity {
              
              @Override
              public void onCreate(android.os.Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  this.getWindow().addFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
              }
          
          }
          

          This approach works on Android 6 but not on Android 11

          QAndroidJniObject activity = QtAndroid::androidActivity();
          if (activity.isValid()) {
              QAndroidJniObject window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;");
              if (window.isValid()) {
                  const int FLAG_KEEP_SCREEN_ON = 128;
                  window.callObjectMethod("addFlags", "(I)V", FLAG_KEEP_SCREEN_ON);
              }
          }
          

          Need programmers to hire?
          www.labcsp.com
          www.denisgottardello.it
          GMT+1
          Skype: mrdebug

          1 Reply Last reply
          2

          • Login

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