DeviceInfo.cs 1.8 KB

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