-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlankBatteryState.cs
More file actions
34 lines (30 loc) · 888 Bytes
/
BlankBatteryState.cs
File metadata and controls
34 lines (30 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using UnityEngine;
#if UNITY_IOS
using System.Runtime.InteropServices;
#endif
/// <summary>
/// 电池电量状态获取
/// </summary>
public sealed class BlankBatteryState
{
#if UNITY_IOS
[DllImport("__Internal")]
private static extern string getBatteryState();
#endif
/// <summary>
/// 获取电量数据 {"status":1,"value":100}
/// status ==> 1 状态未知 2 电池充电中 3 放电中 4 未充电 5 满电量
/// value ==> 电量值
/// </summary>
public static string GetBatteryState()
{
#if UNITY_ANDROID && !UNITY_EDITOR
AndroidJavaClass androidJavaClass = new AndroidJavaClass("com.alianhome.batterystate.MainActivity");
return androidJavaClass.CallStatic<string>("GetBatteryState");
#elif UNITY_IOS && !UNITY_EDITOR
return getBatteryState();
#else
return "{\"status\":2,\"value\":50}";
#endif
}
}