Hi everyone,

I’m working on a research project involving a self-adaptive ML application running directly on an Android smartphone.

The application needs to monitor its own energy consumption at runtime. This is important because energy is one of the optimization objectives: the system evaluates different ML configurations and later uses their energy consumption, together with other objectives such as accuracy, to decide which configuration should be active.

Because of this, I need an on-device and programmatically accessible way of measuring energy. External power meters are not suitable for the final system, since energy monitoring needs to be part of the application itself and available during normal runtime.

I found Android's BatteryManager.BATTERY_PROPERTY_ENERGY_COUNTER, which according to the documentation should return the battery's remaining energy in nanowatt-hours:

batteryManager.getLongProperty(BatteryManager.BATTERY_PROPERTY_ENERGY_COUNTER)

My idea would be to read the counter before and after evaluating a configuration and use the difference as its energy consumption.

However, on my device (Google Pixel 10 Pro), the property appears to be unsupported and returns Long.MIN_VALUE.

Has anyone successfully used BATTERY_PROPERTY_ENERGY_COUNTER, particularly on recent Pixel devices or recent Android versions?

If so, which device/Android version did you use? Did it require any special configuration or permissions, or did getLongProperty() simply return a valid value?

If this property is no longer supported on recent devices, what on-device API or mechanism are you using to obtain energy consumption programmatically from within an Android application?

I’m specifically looking for something that can be queried automatically at runtime — not external measurement equipment or offline profiling tools — because the energy information will ultimately be used by the application itself to make adaptation decisions.

Any experience with BATTERY_PROPERTY_ENERGY_COUNTER or alternative approaches for this use case would be greatly appreciated.

submitted by /u/P-Jorge
[link] [comments]