# How to check the remaining battery level of your controller

**URL:** <https://forum.magicleap.cloud/t/how-to-check-the-remaining-battery-level-of-your-controller/764>\
**Category:** Getting Started\
**Created:** [September 3, 2022, 1:43am UTC](https://forum.magicleap.cloud/t/how-to-check-the-remaining-battery-level-of-your-controller/764 "2022-09-03T01:43:49Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![tokufxug](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/tokufxug/32/172_2.png) [@tokufxug](https://forum.magicleap.cloud/u/tokufxug)\
**Post date:** [September 3, 2022, 1:43am UTC](https://forum.magicleap.cloud/t/how-to-check-the-remaining-battery-level-of-your-controller/764/1 "2022-09-03T01:43:49Z")

</div>

Where can I find the battery level on my Magic Leap 2 controller?  
I could not find it on the following page.

> **[Magic Leap 2 - Controller LED Guide](https://www.magicleap.care/hc/en-us/articles/4416076504589)**
>
> Magic Leap 2's controller has a single LED dot. Different combinations of colors and flashes communicate different pieces of information about the controller's status.
>  
> 
> 
> 
> 
> LED
> Meaning
> 
> 
> 
> 
> Boot up...

Thanks.  
[Sadao Tokuyama](https://www.linkedin.com/in/sadao-tokuyama/)

---

<div class="post-metadata">

**Author:** ![cdorff](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/cdorff/32/30_2.png) [@cdorff](https://forum.magicleap.cloud/u/cdorff)\
**Post date:** [September 6, 2022, 1:07pm UTC](https://forum.magicleap.cloud/t/how-to-check-the-remaining-battery-level-of-your-controller/764/2 "2022-09-06T13:07:35Z")

</div>

We use a sticky intent similar to the **android intent.action.BATTERY\_CHANGED** intent which apps can use to get updates regarding the compute pack battery level and status. Documentation on using the system intent can be found here: [Monitor the Battery Level and Charging State | Android Developers](https://developer.android.com/training/monitoring-device-state/battery-monitoring)

The controller battery intent is named **com.magicleap.controller.action.BATTERY\_CHANGED**. The extras attached to the intent will follow what the system battery intent uses, so that code that processes the system battery intent can be used as the basis for code to process the controller battery intent. The following extras are populated in the controller battery intent:

- If the connection to the controller is active, the following extras will be set:
  - **BatteryManager.EXTRA\_PRESENT** : true
  - **BatteryManager.EXTRA\_LEVEL** : current controller battery level (0-100)
  - **BatteryManager.EXTRA\_SCALE** : 100
  - **BatteryManager.EXTRA\_BATTERY\_LOW** : true if current level is 25% or lower, otherwise false
  - **BatteryManager.EXTRA\_STATUS** : **BatteryManager.BATTERY\_STATUS\_CHARGING** or **BatteryManager.BATTERY\_STATUS\_NOT\_CHARGING** , based on controller charger connection state

- If the connection to the controller is not active, the following extras will be set:
  - **BatteryManager.EXTRA\_PRESENT** : false
  - **BatteryManager.EXTRA\_STATUS** : **BatteryManager.BATTERY\_STATUS\_UNKNOWN**

---

<div class="post-metadata">

**Author:** ![tokufxug](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/tokufxug/32/172_2.png) [@tokufxug](https://forum.magicleap.cloud/u/tokufxug)\
**Post date:** [September 6, 2022, 1:12pm UTC](https://forum.magicleap.cloud/t/how-to-check-the-remaining-battery-level-of-your-controller/764/3 "2022-09-06T13:12:59Z")

</div>

There is no way to see the battery level from the outside, such as by lighting LEDs, as is the case with compute packs.

---

<div class="post-metadata">

**Author:** ![cdorff](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/cdorff/32/30_2.png) [@cdorff](https://forum.magicleap.cloud/u/cdorff)\
**Post date:** [September 6, 2022, 1:34pm UTC](https://forum.magicleap.cloud/t/how-to-check-the-remaining-battery-level-of-your-controller/764/4 "2022-09-06T13:34:39Z")

</div>

Once the controller is paired with the ML2 headset, the controller's battery level is visible in the main menu.

---

<div class="post-metadata">

**Author:** ![tokufxug](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/tokufxug/32/172_2.png) [@tokufxug](https://forum.magicleap.cloud/u/tokufxug)\
**Post date:** [September 6, 2022, 1:42pm UTC](https://forum.magicleap.cloud/t/how-to-check-the-remaining-battery-level-of-your-controller/764/5 "2022-09-06T13:42:40Z")

</div>

I am asking about how to check the Controller's battery level when the Magic Leap 2 is not running.

---

<div class="post-metadata">

**Author:** ![tokufxug](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/tokufxug/32/172_2.png) [@tokufxug](https://forum.magicleap.cloud/u/tokufxug)\
**Post date:** [September 7, 2022, 2:20pm UTC](https://forum.magicleap.cloud/t/how-to-check-the-remaining-battery-level-of-your-controller/764/6 "2022-09-07T14:20:17Z")

</div>

@cdorff One question arose about the Controller's battery status reply in the app.  
It seems to be using the Android Java final variable, but if I want to get the Controller's battery status, do I need to create a native Java library to get the Controller's battery status and import it into Unity?

Or can the program to get the Controller's battery status be completed by just developing Unity?

---

<div class="post-metadata">

**Author:** ![cdorff](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/cdorff/32/30_2.png) [@cdorff](https://forum.magicleap.cloud/u/cdorff)\
**Post date:** [September 7, 2022, 3:14pm UTC](https://forum.magicleap.cloud/t/how-to-check-the-remaining-battery-level-of-your-controller/764/7 "2022-09-07T15:14:14Z")

</div>

This should work in Unity:

[https://docs.unity3d.com/ScriptReference/SystemInfo-batteryLevel.html](https://docs.unity3d.com/ScriptReference/SystemInfo-batteryLevel.html)

---

<div class="post-metadata">

**Author:** ![tokufxug](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/tokufxug/32/172_2.png) [@tokufxug](https://forum.magicleap.cloud/u/tokufxug)\
**Post date:** [September 7, 2022, 3:19pm UTC](https://forum.magicleap.cloud/t/how-to-check-the-remaining-battery-level-of-your-controller/764/8 "2022-09-07T15:19:56Z")

</div>

Isn't this only possible to get the battery level of the Compute Pack?

In the beginning you explained how the Controller gets it from the Controller's intent for the battery, right?

> [@How to check the remaining battery level of your controller](https://forum.magicleap.cloud/t/how-to-check-the-remaining-battery-level-of-your-controller/764/2):
>
> We use a sticky intent similar to the android intent.action.BATTERY\_CHANGED intent which apps can use to get updates regarding the compute pack battery level and status. Documentation on using the system intent can be found here: [Monitor the Battery Level and Charging State | Android Developers](https://developer.android.com/training/monitoring-device-state/battery-monitoring) The controller battery intent is named com.magicleap.controller.action.BATTERY\_CHANGED. The extras attached to the intent will follow what the system battery intent uses, so that code that processes th…

Is there a sample program that has been tested to get the Controller's battery information?

---

<div class="post-metadata">

**Author:** ![cdorff](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/cdorff/32/30_2.png) [@cdorff](https://forum.magicleap.cloud/u/cdorff)\
**Post date:** [September 8, 2022, 2:37pm UTC](https://forum.magicleap.cloud/t/how-to-check-the-remaining-battery-level-of-your-controller/764/9 "2022-09-08T14:37:15Z")

</div>

```auto
public static int GetControllerBatteryState()
    {
#if PLATFORM_ANDROID && !UNITY_EDITOR
      using var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
      var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
      if (activity == null)
      {
        Utils.LogError("Activity is null");
        return -1;
      }
      using var filter = new AndroidJavaObject("android.content.IntentFilter");
      if (filter == null)
      {
        Utils.LogError("IntentFilter is null");
        return -1;
      }
      filter.Call("addAction", "com.magicleap.controller.action.BATTERY_CHANGED");
      using var intent = activity.Call<AndroidJavaObject>("registerReceiver", null, filter);
      if (intent == null)
      {
        Utils.LogError("Intent is null");
        return -1;
      }
      using var batteryManager = new AndroidJavaClass("android.os.BatteryManager");
      if (batteryManager == null)
      {
        Utils.LogError("BatteryManager is null");
        return -1;
      }
      var EXTRA_PRESENT = batteryManager.GetStatic<string>("EXTRA_PRESENT");
      var EXTRA_LEVEL = batteryManager.GetStatic<string>("EXTRA_LEVEL");
      var isPresent = intent.Call<bool>("getBooleanExtra", EXTRA_PRESENT, false);
      return isPresent ? intent.Call<int>("getIntExtra", EXTRA_LEVEL, -1) : -1;
#else
    return -1;
#endif
    }

```

---

<div class="post-metadata">

**Author:** ![tokufxug](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/tokufxug/32/172_2.png) [@tokufxug](https://forum.magicleap.cloud/u/tokufxug)\
**Post date:** [September 8, 2022, 2:59pm UTC](https://forum.magicleap.cloud/t/how-to-check-the-remaining-battery-level-of-your-controller/764/10 "2022-09-08T14:59:58Z")

</div>

Thank you for presenting the sample code so quickly. I can't try it because I don't have a Magic Leap 2 at hand, but I will check it when I can get a Magic Leap 2.
