Englisch version   Deutsche Version


Version Adjustments
1.0 (2020-01-25) Initial version
1.1 (2020-03-07) URL to this page corrected

Motivation

For a future project I want to control a smartphone remotely, i.e. I don't have direct access to the device. For this project, I would like to find out about the battery charge status. The smartphone should be checked by an app created with the App Inventor. Unfortunately there are no corresponding functions there. But you can make it available through a self-made extension.


Download

The ZIP archive UrsAI2Battery for download. The archive contains the source code, the compiled binary for uploading to App Inventor and a sample application.

Features

The extension provides a number of properties that provide information about the battery status. Not all values are available on all smartphone types. In this case, clearly recognizable error values are returned.

Block Typ Funktion Fehlerwert
Remaining Capacity Integer Returns the remaining capacity of the battery in percent. -1
Remaining Charge Integer Returns the remaining charge of the battery in mAh. -1
Remaining Energy Integer Returns the remaining energy of the battery in mWh.
Can be estimated from voltage and residual charge if necessary.
-1
Voltage Integer Returns the current battery voltage in mV. -1
CurrentNow Integer Returns the current power consumption in mA.
A positive value is the discharge current, a negative value is the charge current.
-99999
Currant Average Integer Returns the average current consumption in mA.
A positive value is the discharge current, a negative value is the charge current.
The time period over which the average is calculated may depend on the hardware and its configuration.
-99999
IsCharging Boolean Indicates whether the battery is currently being charged. false

Example

A small sample app shows the use of the extension (see download).

Screenshot You can see that some features are not supported on the test device.

Tools

For developing own extensions I gathered some tips: AI2 FAQ: Develop Extensions.