changhong/wb_unity_pro/Assets/Scripts/Platform/PlatformAndroid.cs

81 lines
1.8 KiB
C#
Raw Normal View History

using UnityEngine;
using System.Collections;
using System;
public class PlatformAndroid :MonoBehaviour
{
public static PlatformAndroid Instance;
void Awake()
{
Instance = this;
}
#if UNITY_ANDROID
AndroidJavaClass _player;
AndroidJavaObject _activity;
void Start()
{
if (Application.platform == RuntimePlatform.Android)
{
//Debug.LogError("初始化安卓==========");
_player = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
_activity = _player.GetStatic<AndroidJavaObject>("currentActivity");
// Debug.LogError("===============");
}
}
public void UpdateApp(string url)
{
if (_activity == null) return;
_activity.Call("__installApk", url);
}
public int GetVersion()
{
if (_activity == null) return 0;
return _activity.Call<int>("__getVersion");
}
public void ShareLink(int id, string json_data)
{
if (_activity == null) return;
_activity.Call("__shareLink", id, json_data, "OnShareAction");
}
public void WXLogin()
{
if (_activity == null) return;
//Debug.LogError("开始微信登录===============");
_activity.Call("__auth", 1,"");
//Debug.LogError("开始微信登录===============1111111111111111111111111111111111111111111");
}
public void CopyTextToClipboard(string input)
{
if (_activity == null) return;
_activity.Call("__copyTextToClipboard", input);
}
public float GetBatteryLevel()
{
if(_activity == null) return 100;
return _activity.Call<float>("__getBattery");
}
public string GetRoomID()
{
if (_activity == null) return "";
return _activity.Call<string>("__getRoomID");
}
#endif
}