Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here: unity.com/legal/terms-of-service.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

[Solved] Unable to call a Native Java Android boolean static method (Other types just work fine)

Discussion in 'Android' started by Shbli, Aug 18, 2016.

  1. Shbli

    Shbli

    Joined:
    Jan 28, 2014
    Posts:
    126
    I though I would ask if this problem is happening for anyone else.

    I am working on a Unity --> Android plugin, and I found out that surprisngly, though most of the things went well, I'm unable to call a static bool methods in my Java class, within the same class, I'm able to call methods with return types of "void" and "string", so as a temporary solution I'm using a string with "TRUE" and "FALSE" as a return string.

    When I logcat, I get the exception that the method was not found, with signature "v" which means that it is trying to find a bool I believe, but some strange thing is that it says that it is "Unable to find non static methods", where I'm 100% sure my methods is static and I'm using "CallStatic" in C#

    Here is my Java method:
    Code (CSharp):
    1.  
    2.     private static Boolean isActivityDone = false;
    3.     public static Boolean IsActivityDone()
    4.     {
    5.         return isActivityDone;
    6.     }
    Here is my C# way of calling it:
    Code (CSharp):
    1. googleLoginAndroidJavaClass.CallStatic<bool>("IsActivityDone");
    The above does not work, but here is the changes and it works

    Java code
    Code (CSharp):
    1.     private static String isActivityDone = "FALSE";
    2.     public static String IsActivityDone()
    3.     {
    4.         return isActivityDone;
    5.     }
    6.  
    C# code
    Code (CSharp):
    1. googleLoginAndroidJavaClass.CallStatic<string>("IsActivityDone");
    I'm using Unity 5.4.0 and the latest version of Android studio to develop the plugin
     
    Last edited: Aug 18, 2016
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,519
    What is the error message you are getting?

    I think you should read this post: http://stackoverflow.com/q/1295170
    The Java method should return a boolean, not a Boolean.
     
    Havokki and Shbli like this.
  3. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,160
    A Boolean has a signature of "Z". More details/logs would be appreciated.
     
    Havokki and Shbli like this.
  4. Shbli

    Shbli

    Joined:
    Jan 28, 2014
    Posts:
    126
    That works! Thanks.
     
unityunity