Battery Information

Battery information can be retrieved for connected devices. For Android™ devices using Android Debug Bridge (ADB), and for iOS devices an in-built build of libimobile.

ADB can be used to query the battery level on any Android™ devices providing a few conditions are met.

  • The Android platform tools are installed, these can be downloaded from here.

  • The ADB binary is in the path, or it’s path is provided to the API via cbrx_config_set.

  • The device has USB debugging enabled.

  • You have trusted the computer from the phone if the phone requires it.

See this page for details on enabling debug mode on Android™ devices. The only options that are required are to enable developer mode and USB debugging.

Copy
# Install Android platform tools on Linux sudo apt install
        Android-platform-tools#   # Install Android platform tools on macOS
        brew cask install Android-platform-tools   # Install Android
        platform tools on Windows # Goto
        https://developer.Android.com/studio/releases/platform-tools # Download
        SDK Platform-Tools for Windows # Extract and add the folder to your path
        or use # cbrx_config_set("adb_path" <pathname>) to add to API
        settings.
Finding adb without the path

Alternatively from setting the path, we can tell the API where to find these programs.

Copy
{
  "jsonrpc": "2.0",
  "id": 0,
  "method": "cbrx_config_set",
  "params": {
    "adb_path": "/usr/local/bin"
  }
}
Mobile-device battery trust-levels

To obtain the battery information on mobile devices (phones / tablets) the device must be paired with the host system. To pair a device you will need to trust the host system on the mobile device when first connecting. There are various trust levels which are documented below.

Trust level Description
"not-paired" Device not paired
"paired" Device paired
"pending" Battery information pending
"failed" Failed to obtain battery information
"prohibited" Prohibited from obtaining battery information
"error" Error on obtaining battery information