| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- /*
- * File Name: AmlogicJarSend
- * Author: Guan B
- * Version: 1.0.0
- * Data: 2022.04.08
- * Des: 发送数据给Android端
- * Other: Zeewain
- */
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- /*
- using static System.Net.Mime.MediaTypeNames;*/
- public class AmlogicJarSend : MonoBehaviour
- {
- public static AmlogicJarSend single;
- private AndroidJavaClass jc;
- private AndroidJavaObject jo;
- // public Button btn;
- /* public Text text;*/
- int num = 0;
- // byte[] photo;
- string str = "{\"body\":null,\"cmd\":100,\"seq\":1,\"state\":0}";
- string str2 = "{\"body\":null,\"cmd\":104,\"seq\":1,\"state\":0}";
- void Awake()
- {
- single = this;
- //print("已进入Awake");
- if (Application.platform == RuntimePlatform.WindowsEditor
- || Application.platform == RuntimePlatform.WindowsPlayer)
- {
- }
- if (Application.platform == RuntimePlatform.Android)// 使用Unity切换Platform无法模拟
- {
- print("开始调用AndroidJavaClass");
- //这两行是固定写法
- jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
- jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
- // btn.onClick.AddListener(OnBtnClickHandler);
- print("成功调用AndroidJavaClass");
- // send("发送测试");
- send(str);
- send(str2);
- print("发送104协议");
- }
- }
- // public Webcam_Test web_tex;
- public void OnBtnClickHandler()
- {
- if (Application.platform == RuntimePlatform.Android)// 使用Unity切换Platform无法模拟
- {
- //调用Android中的方法UnityCallAndroid
- jo.Call("UnityCallAndroid");
- // num = jo.CallStatic<int>("GetNum");
- num = jo.Call<int>("Setting");
- }
- }
- public void send(string str)
- {
- print("开始发送消息给AndroidJavaClass" + str);
- jo.Call("OnUnityMsg", 1, str);
- print("成功发送消息给AndroidJavaClass");
- }
- }
|