Aymeric Schaeffer
Aymeric Schaeffer

Reputation: 1

Search for a workaround to trigger battery measurement updates on Android

I'm a computer science student working on an android battery diagnostic app for a startup. I've taken the Android Kotlin training course to develop his app but being a beginner I'm having a problem: Android prevents me from mastering the updating of the phone's battery voltage and temperature.

The current updates very regularly, so I don't have a problem with that. However, voltage and temperature update every 10 seconds, sometimes every minute, and this causes me problems because I need to get values every second, the best thing for me would be every 100ms.

I use the BatteryManager API to retrieve current, voltage and temperature values: https://developer.android.com/reference/android/os/BatteryManager After reading the documentation, I understand that I need to retrieve the intent EXTRA_VOLTAGE and EXTRA_TEMPERATURE from the ACTION_BATTERY_CHANGED protected event. Since it's protected, I can't trigger it myself. https://developer.android.com/reference/android/os/BatteryManager#EXTRA_VOLTAGE

This is a big problem for me, as the algorithm I'm implementing can't do without these values. My constraint is that I can't trigger this event via an external action such as unplugging/replugging the smartphone, which effectively updates the voltage/current values, but disrupts my current measurement.

I already tried to trigger the intent, but it resulted in a 'permission denied'-like message.

Even though I don't have to use an external tool, I've tried to trigger the event via the ADB tool, by modifying certain parameters such as battery level or charging status, but it doesn't work.

Since I can't use an external tool, I'm desperately looking for a way to trigger the ACTION_BATTERY_CHANGED event (or another event with the same impact?) to update the voltage/current values from my app.

I'm calling on the expert community to help me find a workaround to successfully update the voltage despite the operating system's protection.

Thank you in advance for your invaluable help.

Upvotes: 0

Views: 27

Answers (0)

Related Questions