Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-49853

Unable to call PowerManager.WakeLock.newWakeLock using QAndroidJniObject

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.5.0
    • QPA
    • None
    • Android

    Description

      I'm trying to execute this Java code:

          PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
          PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
          wl.acquire();
      

      using Qt QAndroidJniObject (I'm deploying a Qt app on Android).

      I did that:

          QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");
          if ( activity.isValid() )
          {
              QAndroidJniObject serviceName = QAndroidJniObject::getStaticObjectField<jstring>("android/content/Context","POWER_SERVICE");
              if ( serviceName.isValid() )
              {
                  QAndroidJniObject powerMgr = activity.callObjectMethod("getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;",serviceName.object<jobject>());
                  if ( powerMgr.isValid() )
                  {
                      QAndroidJniObject wakeLock = powerMgr.callObjectMethod("newWakeLock", "(ILjava/lang/String;)Landroid/os/PowerManager/WakeLock;", levelAndFlags,tag.object<jstring>());
      
                      if ( wakeLock.isValid() )
                          wakeLock.callMethod<void>("acquire", "()V");
                      else
                          assert( false );
                  }
              }
          }
      
      

      Checked from the debugger: `levelAndFlags` is correct (6), `tag` is correct ("My Tag"), but `wakeLock.isValid()` returns false.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              esabraha Eskil Abrahamsen Blomfeldt
              jpo38 Jean Porcherot
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes