Steps
No more nonsense, just go ahead.
1. Create a project and make it look like this interface
2. Write code in unity, like this, and remember to bind the interface to events.
Using Unityengine;Using Unityengine.ui;PublicClassTestScripts:Monobehaviour {Public Inputfield m_inputfiled;Public Text M_label;PublicvoidOnClickButton1 () {Androidjavaclass JC =New Androidjavaclass ("Com.unity3d.player.UnityPlayer"); Androidjavaobject Jo = JC. Getstatic<androidjavaobject> ("CurrentActivity"); Jo. Call ("U3d_showtoast1"); }PublicvoidOnClickButton2 (new androidjavaclass (" Com.unity3d.player.UnityPlayer "); Androidjavaobject Jo = JC. Getstatic<androidjavaobject> ( "currentactivity"); Jo. Call ( "U3d_showtoast2", M_inputfiled.text);} public void onclickbutton3 (new androidjavaclass ( "Com.unity3d.player.UnityPlayer"); Androidjavaobject Jo = JC. Getstatic<androidjavaobject> ( "currentactivity"); m_label.text = Jo. Call<string> ( "U3d_getvalue");}}
3. Export Android Project
4. Import the project into eclipse
5. Find the corresponding activity
6. Add the appropriate code to the activity
7. Package Run
Click the first button
After entering text in a text box, click the second button
Click the third button and the label word changes to Android return text
Unity calls Android method