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

Using JNI

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
17 Posts 4 Posters 3.3k Views 2 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.
  • NickVN Offline
    NickVN Offline
    NickV
    wrote on last edited by
    #1

    Hi,
    i want to do the following with Qt QAndroidJniObject:

    wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "My Tag");
    

    The problem is that i can not do the pipe ( | ) with qt.
    My code is

    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() )
               {
                   jint levelAndFlags = QAndroidJniObject::getStaticField<jint>("android/os/PowerManager","SCREEN_DIM_WAKE_LOCK");
    
                   QAndroidJniObject tag = QAndroidJniObject::fromString( "My Tag" );
    
                   m_wakeLock = powerMgr.callObjectMethod("newWakeLock", "(ILjava/lang/String;)Landroid/os/PowerManager$WakeLock;", levelAndFlags,tag.object<jstring>());
               }
           }
       }
    

    Anu help????

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      For me it looks like an binary OR of enum values. ( like setFlags)
      ( PowerManager.SCREEN_DIM_WAKE_LOCK OR'ED PowerManager.ACQUIRE_CAUSES_WAKEUP )
      But in java this mean some else?

      aha_1980A 1 Reply Last reply
      1
      • mrjjM mrjj

        Hi
        For me it looks like an binary OR of enum values. ( like setFlags)
        ( PowerManager.SCREEN_DIM_WAKE_LOCK OR'ED PowerManager.ACQUIRE_CAUSES_WAKEUP )
        But in java this mean some else?

        aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @mrjj said in Using JNI:

        Hi
        For me it looks like an binary OR of enum values. ( like setFlags)
        ( PowerManager.SCREEN_DIM_WAKE_LOCK OR'ED PowerManager.ACQUIRE_CAUSES_WAKEUP )
        But in java this mean some else?

        I think it's exactly the same in Java and C++

        Qt has to stay free or it will die.

        1 Reply Last reply
        1
        • NickVN Offline
          NickVN Offline
          NickV
          wrote on last edited by
          #4

          Could you please give a sample of code?
          I don't understand what exactly i have to do.

          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #5

            Hi
            Syntax should be the same.
            https://www.somacon.com/p125.php
            For the OR part but are you talking about the actual pm.newWakeLock call or
            simply the
            PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP ?

            1 Reply Last reply
            0
            • NickVN Offline
              NickVN Offline
              NickV
              wrote on last edited by
              #6

              If i use | this cause error. It says that there is not such flag.

              mrjjM 1 Reply Last reply
              0
              • NickVN NickV

                If i use | this cause error. It says that there is not such flag.

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @NickV
                Hi
                can you show exact error ?
                Maybe it just dont know PowerManager.SCREEN_DIM_WAKE_LOCK etc.

                1 Reply Last reply
                0
                • NickVN Offline
                  NickVN Offline
                  NickV
                  wrote on last edited by
                  #8
                  java.lang.NoSuchFieldError: no "I" field "SCREEN_DIM_WAKE_LOCK|ACQUIRE_CAUSES_WAKEUP" in class "Landroid/os/PowerManager;" or its superclasses
                  
                  mrjjM 1 Reply Last reply
                  0
                  • NickVN NickV
                    java.lang.NoSuchFieldError: no "I" field "SCREEN_DIM_WAKE_LOCK|ACQUIRE_CAUSES_WAKEUP" in class "Landroid/os/PowerManager;" or its superclasses
                    
                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @NickV
                    Oh, we read it all completely wrong.
                    Its not in c++ , but java ?

                    1 Reply Last reply
                    0
                    • NickVN Offline
                      NickVN Offline
                      NickV
                      wrote on last edited by NickV
                      #10

                      I am using QAndroidJniObject in order to call power manager and set cpu flags. The code is the above code that i've posted. Look the initial post.

                      mrjjM 1 Reply Last reply
                      0
                      • NickVN NickV

                        I am using QAndroidJniObject in order to call power manager and set cpu flags. The code is the above code that i've posted. Look the initial post.

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @NickV
                        Hi
                        Seems like it dont know
                        PowerManager.SCREEN_DIM_WAKE_LOCK
                        Do you know where its normally defined ?

                        1 Reply Last reply
                        1
                        • NickVN Offline
                          NickVN Offline
                          NickV
                          wrote on last edited by
                          #12

                          No. If i use only SCREEN_DIM_WAKE_LOCK no error produced. Look this link

                          mrjjM 1 Reply Last reply
                          0
                          • NickVN NickV

                            No. If i use only SCREEN_DIM_WAKE_LOCK no error produced. Look this link

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            @NickV
                            But it dont work without PowerManager.ACQUIRE_CAUSES_WAKEUP ?

                            1 Reply Last reply
                            0
                            • NickVN Offline
                              NickVN Offline
                              NickV
                              wrote on last edited by
                              #14

                              No it works but i need this extra flag in order to do some work.

                              mrjjM 1 Reply Last reply
                              0
                              • NickVN NickV

                                No it works but i need this extra flag in order to do some work.

                                mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                @NickV
                                But did u look where SCREEN_DIM_WAKE_LOCK is defined ?
                                Does it define the ACQUIRE_CAUSES_WAKEUP at all ?
                                maybe it was added in later version of the SDK.

                                1 Reply Last reply
                                1
                                • NickVN Offline
                                  NickVN Offline
                                  NickV
                                  wrote on last edited by
                                  #16

                                  Ok! Thanks for your response!

                                  raven-worxR 1 Reply Last reply
                                  0
                                  • NickVN NickV

                                    Ok! Thanks for your response!

                                    raven-worxR Offline
                                    raven-worxR Offline
                                    raven-worx
                                    Moderators
                                    wrote on last edited by
                                    #17

                                    @NickV
                                    For me something is not clear, did you already try the following or not?!

                                    jint levelAndFlags = QAndroidJniObject::getStaticField<jint>("android/os/PowerManager","SCREEN_DIM_WAKE_LOCK") | QAndroidJniObject::getStaticField<jint>("android/os/PowerManager","ACQUIRE_CAUSES_WAKEUP");
                                    

                                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                                    If you have a question please use the forum so others can benefit from the solution in the future

                                    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