Original address: http://blog.csdn.net/u012085988/article/details/17436191
1. Unity Tune Android function
[CSharp]View Plaincopy
- Androidjavaclass JC = new Androidjavaclass ("Com.unity3d.player.UnityPlayer");
- Androidjavaobject activity = JC. Getstatic<androidjavaobject> ("currentactivity");
- Activity. Call ("func")
Activity is the current Activity,call function prototype call<re-type> (FName, args). Within the angle brackets is the return value, the first argument is the function name, the second is the argument
Note: The number of arguments
1, the number is the same, and more than 1. Executable
2. Unity brings in fewer parameters than Android defines. Error: Nosuchmethoderror
3. Unity brings in more parameters than the number of Android-defined parameters. Error: Nosuchmethoderror
Note: When the Android side has overloaded functions
According to the parameter table, find the corresponding function
Note: The JNI is based on similar (ljava/lang/string; Ljava/lang/string;i) v This format to match the function. So the number of parameters, parameter type must be one by one corresponding
2. Android Callback Unity function
[CSharp]View Plaincopy
- Unityplayer.unitysendmessage ("Androidmanager", "Androidcallbackunlockgame", " " ");
The first argument is Gameobject, the second argument is the function name, and the third is the argument (string)
Note: The names are case-sensitive. and the parameter type, the number of parameters should be corresponding to each.
Note: The third argument cannot be null, to pass an empty string, you can write "", but you cannot write null. Otherwise it will crash!
3. UI processing in Android
[CSharp]View Plaincopy
- Runonuithread (new Runnable () {
- public Void Run () {
- Text (msg);
- }
- });