- Home /
Question by
AshishAxiom · May 31, 2013 at 12:59 PM ·
c#androidandroidplugin
calling java method from unity c#
Hello everyone, Can anyone tell me how to call java methods from unity c#. I tried the following but its not working for me.
In Unity :
void OnGUI () {
string somestring;
AndroidJavaClass jc= new AndroidJavaClass("com.example.pluginsample.MainActivity");
AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("instance");
somestring = jo.Call<string>("Foo");
GUI.Label (new Rect (20, 20, 100, 20), somestring);
}
In Java Class:
public String Foo()
{
return "Hello";
}
Comment
Answer by knighthedspi · Aug 05, 2014 at 09:44 AM
You missed the return type. Your code should be modified like this
AndroidJavaObject jo = jc.GetStatic <AndroidJavaObject>("instance");
string somestring = jo.Call<string>("Foo");
After that,put your compiled jar file in Assets/Plugins/Android in your project
Your answer
Follow this Question
Related Questions
cant delay with WaitForSeconds C# 2 Answers
Share Button 3 Answers
How to pass context from unity to Kotlin library 0 Answers
Distribute terrain in zones 3 Answers
Android Plugin Help 1 Answer