I try make a plugin in android studio to use in Unity.
So I make this method in android studio.
public class MainActivity extends UnityPlayerActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public static String SendMessage(){
return "Message";
}
}
and in Unity,
public class PluginWrapper : MonoBehaviour {
// Use this for initialization
void Start () {
TextMesh textMesh = GetComponent<TextMesh> ();
var plugin = new AndroidJavaClass ("com.thewell_dev.beaconf.MainActivity");
textMesh.text = plugin.CallStatic<string> ("ReturnMessage");
}
}
to use SendMessage() method in unity, using AndroidJavaClass and CallStatic.
It is success.
I can check message in device by unity.
But, one error occurs.
If I change method like this,
public class MainActivity extends UnityPlayerActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public String SendMessage(){
return "Message";
}
}
change SendMessage method type.(static String to String)
and in Unity,
public class PluginWrapper : MonoBehaviour {
// Use this for initialization
void Start () {
TextMesh textMesh = GetComponent<TextMesh> ();
var plugin = new AndroidJavaClass ("com.thewell_dev.beaconf.MainActivity");
textMesh.text = plugin.Call<string> ("ReturnMessage");
}
}
change plugin.CallStaic to plugin.Call
In case, I just delete Static, but it returns no result.
https://docs.unity3d.com/kr/current/ScriptReference/AndroidJavaClass.html
I just change the type. But no returns.
I think I mistake to Call method by AndroidJavaClass,
but I can't find it.
If you know about it, Please help me.