Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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,562
    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,167
    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.