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 do I return bool from Android Java code?
Forum Update on Monday, May 27th 2025

How do I return bool from Android Java code?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
4 Posts 3 Posters 956 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.
  • A Offline
    A Offline
    Allstar12345
    wrote on 23 Apr 2020, 14:20 last edited by
    #1

    I'm new to Android and JNI stuff, I basically need to return a boolean from some android java code,

    Now looking at an example I can get a string to return but not sure how to go about returning a bool

    Currently have test.java:

        import org.qtproject.qt5.android.bindings.QtApplication;
        import org.qtproject.qt5.android.bindings.QtActivity;
        import android.content.res.Configuration;
     
        public class test extends QtActivity
        {    
    
    
        public static String printBob(int a)
        {
          return "hello bob";
        }
    
    public boolean teste(){
    
        Configuration config = getResources().getConfiguration();
        return config.isScreenRound();
    
        };
    
        }
    
    

    Now the printBob() works fine from:

    QAndroidJniObject str = QAndroidJniObject::callStaticObjectMethod("test",
                                           "printBob",
                                           "(I)Ljava/lang/String;"
                                           );
    
        return str.toString();
    

    But I'm not sure how to call the teste() function to return the bool

    Thanks

    K 1 Reply Last reply 23 Apr 2020, 16:39
    0
    • A Allstar12345
      23 Apr 2020, 14:20

      I'm new to Android and JNI stuff, I basically need to return a boolean from some android java code,

      Now looking at an example I can get a string to return but not sure how to go about returning a bool

      Currently have test.java:

          import org.qtproject.qt5.android.bindings.QtApplication;
          import org.qtproject.qt5.android.bindings.QtActivity;
          import android.content.res.Configuration;
       
          public class test extends QtActivity
          {    
      
      
          public static String printBob(int a)
          {
            return "hello bob";
          }
      
      public boolean teste(){
      
          Configuration config = getResources().getConfiguration();
          return config.isScreenRound();
      
          };
      
          }
      
      

      Now the printBob() works fine from:

      QAndroidJniObject str = QAndroidJniObject::callStaticObjectMethod("test",
                                             "printBob",
                                             "(I)Ljava/lang/String;"
                                             );
      
          return str.toString();
      

      But I'm not sure how to call the teste() function to return the bool

      Thanks

      K Offline
      K Offline
      koahnig
      wrote on 23 Apr 2020, 16:39 last edited by
      #2

      @Allstar12345

      Under https://doc.qt.io/qt-5/qandroidjniobject.html#details

      9c6ea555-f303-464c-b09f-600b65b31c02-image.png

      Vote the answer(s) that helped you to solve your issue(s)

      A 1 Reply Last reply 23 Apr 2020, 20:06
      0
      • K koahnig
        23 Apr 2020, 16:39

        @Allstar12345

        Under https://doc.qt.io/qt-5/qandroidjniobject.html#details

        9c6ea555-f303-464c-b09f-600b65b31c02-image.png

        A Offline
        A Offline
        Allstar12345
        wrote on 23 Apr 2020, 20:06 last edited by
        #3

        @koahnig I read that initially, the signature for string is of course

        (I)Ljava/lang/String;
        

        I get that bit, but whatever i put in the last argument fails, I'm new to this stuff it doesn't really make sense

        
            QAndroidJniObject str = QAndroidJniObject::callStaticObjectMethod("test",
                                                   "teste",
                                                   "(I)Z");
        
        K 1 Reply Last reply 23 Apr 2020, 21:50
        0
        • A Allstar12345
          23 Apr 2020, 20:06

          @koahnig I read that initially, the signature for string is of course

          (I)Ljava/lang/String;
          

          I get that bit, but whatever i put in the last argument fails, I'm new to this stuff it doesn't really make sense

          
              QAndroidJniObject str = QAndroidJniObject::callStaticObjectMethod("test",
                                                     "teste",
                                                     "(I)Z");
          
          K Offline
          K Offline
          KroMignon
          wrote on 23 Apr 2020, 21:50 last edited by
          #4

          @Allstar12345 You have to use full name, with package.
          For example if your class test is in package com.mycompany.application:

           QAndroidJniObject str = QAndroidJniObject::callStaticObjectMethod("com/mycompany/application/test",
                                                     "teste",
                                                     "(I)Z");
          

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          1 Reply Last reply
          0

          1/4

          23 Apr 2020, 14:20

          • Login

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