AndroidBatteryStatus.cs 432 B

12345678910111213141516
  1. using UnityEngine;
  2. public class AndroidBatteryStatus : MonoBehaviour
  3. {
  4. private AndroidJavaObject androidPlugin;
  5. void Start()
  6. {
  7. // 创建Android插件实例
  8. androidPlugin = new AndroidJavaObject("com.example.androidbatteryplugin.BatteryPlugin");
  9. // 获取电池电量
  10. int batteryLevel = androidPlugin.Call<int>("GetBatteryLevel");
  11. Debug.Log("Battery Level: " + batteryLevel + "%");
  12. }
  13. }