AndroidDevice.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. 
  2. using SC.XR.Unity.Module_InputSystem;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. namespace SC.XR.Unity.Module_Device {
  8. [Serializable]
  9. public class AndroidDevice : DeviceBase {
  10. public AndroidDeviceType type;
  11. /// <summary>
  12. /// 设备型号
  13. /// </summary>
  14. /// <returns></returns>
  15. public override string MODEL {
  16. get {
  17. AndroidJavaClass os = new AndroidJavaClass("android.os.Build");
  18. return os.GetStatic<string>("MODEL");
  19. }
  20. }
  21. /// <summary>
  22. /// SN号
  23. /// </summary>
  24. public override string SN {
  25. get {
  26. AndroidJavaClass os = new AndroidJavaClass("android.os.Build");
  27. return os.GetStatic<string>("SERIAL");
  28. }
  29. }
  30. /// <summary>
  31. /// Release_Vesion
  32. /// </summary>
  33. public override string RELEASE_VERSION {
  34. get {
  35. AndroidJavaClass os = new AndroidJavaClass("android.os.Build$VERSION");
  36. return os.GetStatic<string>("RELEASE");
  37. }
  38. }
  39. /// <summary>
  40. /// BatteryLevel
  41. /// </summary>
  42. public override int BatteryLevel {
  43. get {
  44. try {
  45. string CapacityString = System.IO.File.ReadAllText("/sys/class/power_supply/battery/capacity");
  46. return int.Parse(CapacityString);
  47. } catch (Exception e) {
  48. Debug.Log("Failed to read battery power; " + e.Message);
  49. }
  50. return 60;
  51. }
  52. }
  53. public override void ShowInfo() {
  54. base.ShowInfo();
  55. DebugMy.Log(" *** Device Info *** "
  56. + " DeviceType:" + type
  57. , this, true);
  58. }
  59. }
  60. }