Calling Android's API from Unity

Hi All,

I’m new to Unity (kind of…I’ve started to study Unity 2 months ago).
I want to develop game for the Android platform (And of course to buy Unity for Android) but is it possible to
call Android’s native API method and classes within Unity? after all Android’s API is written in Java and I use C# when scripting within Unity 3.3

Thank u in advance

Eyal

There is indeed.

You can learn about calling java code and and native code here and it’s also useful to know how to Integrate Unity and Eclipse.

Hi,

I have quite the same “problem” I have an external API in java I want to use in unity. I have read the full section on Android Plugins / native code / and calling java here on unity3d support section. I have come with the solution below.

  • Simple Function in my java class. ( The class name is : Gree )
    public String test(){
    return “test”;
    }

  • here is my bridge in c# to access the function test into my .jar file.
    public class Gree : MonoBehaviour
    {
    public static void useHasToken(){
    AndroidJavaObject jo = new AndroidJavaObject(“jp.gree.android.sdk.Gree”);
    string test = jo.Call(“test”);
    Debug.Log(test);
    }
    }

When I run directly on the unity editor, I get a Log (“null”) into the console.
When I run on my android device (galaxy S) The application crash when the useHasToken Function is called and I get an error of : java.lang.noSuchMethodException.

I would like some feedback from people already integrated java API in Unity !

Thanks !
BerzerkBed