- Home /
Unity 4.x call android method???
I use AndroidJavaClass and AndroidJavaObject.
But my device return error.
02-26 17:56:34.391: E/Unity(9169): ! getMethodID("initPlasma", "(Ljava/lang/String;)V") FAILED!
02-26 17:56:34.391: E/Unity(9169): JNI: Unable to find method id for 'initPlasma'
//used Unity 4.x code
try
{
using (AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
using (AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity"))
{
jo.Call(JavaMethods.initPlasma, "unity to android");
}
}
}
catch (Exception e)
{
Debug.Log(e.StackTrace);
}
export Eclipse project used Unity 4.x.
and I fixed extends UnityPlayerActivity. ex) class mainActivity extends UnityPlayerActivity
and Added code.
public void initPlasma(final String unityMessage)
{
runOnUiThread(new Runnable() {
public void run()
{
UnityPlayer.UnitySendMessage("targetUnityObj", "OnInitCompleate", unityMessage + " and android to unity");
}
});
}
How can I edit it?
Answer by mobidix · Feb 28, 2013 at 03:00 AM
Many tutorial say change Activity -> UnityPlayerActivity.
But, my case still use Activity.
public class myAppActivity extends Activity
and myAppProxyActivity onCreate method, supportsNative value set false.
boolean supportsNative = Build.VERSION.SDK_INT >= 9 /*Build.VERSION_CODES.GINGERBREAD*/;
supportsNative = false;
Your answer
Follow this Question
Related Questions
Call non-static method (from subclass) in Java from Unity 1 Answer
AndroidJavaClass. Call returns null ptr. 1 Answer
What is the difference between AndroidJavaClass.Call and AndroidJavaObject.Call 2 Answers
AndroidJavaObject as array for NFC access 1 Answer
Running legacy Unity 4.2.1 on legacy MacOS 10.8 in current days 0 Answers