4

So i've integrated my project with eclipse and make calls to my Java classes through C# calls:

AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
jo.Call("Trigger");

Now providing I dont try to pass any arguments along with the Trigger method call, it calls the method perfectly. However, if i try to pass the variable through as follows:

jo.Call("Trigger", "my string");

The unity engine thinks the mystring arg is referring to the signature type of the method being called. How can i pass variables through along to my Java method?

On top of this, how do i return variables from java to C#? Would it be as simple as

String myString = jo.Call("Trigger");

Thanks for the help in advance!

1 Answer 1

3

Try doing it like this. It is working for me:

using(AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
     using(AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity"))
     {
          jo.Call("Trigger", "my string");
     }
}

And then in Eclipse you do:

void Trigger(String message)
{
     if(message=="my string")...
}

Sending variable from java to C#: In eclipse you do:

UnityPlayer.UnitySendMessage("Android", "ReceiveVar", "some string");

Where "Android" is Script containing "ReceiveVar(string str)" function, and "some string" is your variable (this is Unity part).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.