DeviceInfo.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. [Obsolete("Please Use Module_Device")]
  7. public class DeviceInfo {
  8. /// <summary>
  9. /// 设备型号
  10. /// </summary>
  11. /// <returns></returns>
  12. public static string MODEL {
  13. get{
  14. if(Application.platform == RuntimePlatform.Android) {
  15. AndroidJavaClass os = new AndroidJavaClass("android.os.Build");
  16. return os.GetStatic<string>("MODEL");
  17. }
  18. return "Standalone";
  19. }
  20. }
  21. /// <summary>
  22. /// SN号
  23. /// </summary>
  24. public static string SN {
  25. get {
  26. if(Application.platform == RuntimePlatform.Android) {
  27. AndroidJavaClass os = new AndroidJavaClass("android.os.Build");
  28. return os.GetStatic<string>("SERIAL");
  29. }
  30. return "Null";
  31. }
  32. }
  33. /// <summary>
  34. /// Release_Vesion
  35. /// </summary>
  36. public static string RELEASE_VERSION {
  37. get {
  38. if(Application.platform == RuntimePlatform.Android) {
  39. AndroidJavaClass os = new AndroidJavaClass("android.os.Build$VERSION");
  40. return os.GetStatic<string>("RELEASE");
  41. }
  42. return "Null";
  43. }
  44. }
  45. /// <summary>
  46. /// BatteryLevel
  47. /// </summary>
  48. public static int BatteryLevel {
  49. get {
  50. if (Application.platform == RuntimePlatform.Android) {
  51. try {
  52. string CapacityString = System.IO.File.ReadAllText("/sys/class/power_supply/battery/capacity");
  53. return int.Parse(CapacityString);
  54. } catch (Exception e) {
  55. Debug.Log("Failed to read battery power; " + e.Message);
  56. }
  57. }
  58. return 60;
  59. }
  60. }
  61. }