Questions tagged [batterymanager]

The BatteryManager class contains strings and constants used for values in the ACTION_BATTERY_CHANGED Intent.

The BatteryManager class contains strings and constants used for values in the ACTION_BATTERY_CHANGED Intent.

130 questions
63
votes
9 answers

Check if device is plugged in

My app has a broadcast receiver to listen for changes to ACTION_POWER_CONNECTED, and in turn flag the screen to stay on. What I am missing is the ability for the app to check the charging status when it first runs. Can anyone please help me with…
Josh
  • 2,685
  • 6
  • 33
  • 47
12
votes
2 answers

How to test battery charging speed?

How can I detect battery charging speed in android device? I can detect battery status using below code. but not charging speed. IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_BATTERY_CHANGED); BatteryChangeReceiver…
Kishan Vaghela
  • 7,678
  • 5
  • 42
  • 67
11
votes
1 answer

How to keep playback active after the screen is turned off

I have an app with audio playback, but on some devices (mainly Huawei, Samsung, Sony) playback is stopped when the screen goes off. Note: playback does not stop for some other apps like Spotify, Play Music I found this answer (for Huawei devices)…
11
votes
2 answers

Total Battery Capacity in mAh of device Programmatically

I have tried powerprofile of Android....I have tried this code...but it gives me 1000 answer every time in all the devices... Is there any other way in android to get battery capacity... Eg.if mobile device capacity is 2000mAh it should return me…
Jay Poojara
  • 121
  • 1
  • 1
  • 7
9
votes
1 answer

how to determine battery level of airpods in swift

I have been learning about swift for sometimes. I have made an test app that shows user Battery Level and Storage details of the phone. Now i am exploring other possibilities. Is there anyway i can show the Battery Level of AirPods that are…
Nazmul Hasan
  • 123
  • 6
7
votes
0 answers

Change battery optimization programmatically on Android

My app plays streamed audio in the background using Exoplayer but the system is shutting it down if the user doesn't whitelist us manually in the battery optimization settings. There are other apps also running streamed audio in the background…
neowinston
  • 7,584
  • 10
  • 52
  • 83
6
votes
0 answers

BatteryManager Health values "9"

I get a "9" value from BatteryManager. What does it mean? Can anyone know this? Here is my code for what I want: int health = batteryIntent.getIntExtra(BatteryManager.EXTRA_HEALTH, 0); Research area. BatteryManager Health…
Yogesh Rathi
  • 6,331
  • 4
  • 51
  • 81
6
votes
1 answer

Is there any way to find out that android mobile's battery is not usable anymore and we need to change it, programmatically?

I looked everywhere for this, all I am getting is getting the battery related data via BatteryManager which I already know. But the thing is it always return battery health as "BATTERY_HEALTH_GOOD" . To cross check the same I checked various battery…
Ankit Purwar
  • 522
  • 5
  • 18
5
votes
1 answer

Foreground service is killed in Android 10

In Android 10, some manufacturer comes with the new feature in a battery optimization setting (see the picture). My foreground service getting killed by OS after some time when the screen is off. I have used the foreground service with notification.…
mdroid
  • 474
  • 3
  • 15
5
votes
3 answers

Calculating remaining time of battery live

Is it possible to calculate remaining battery time in hours and minutes? Also, would it be able to calculate this time depending on if I'm using a certain app? Is it even possible to get such information? If you could please give me advice on how to…
Ambitious Person
  • 295
  • 1
  • 3
  • 15
4
votes
2 answers

Socket.IO With Service Draining Battery Dramatically (Android)

Good day. I have a question considering the most best practise for battery managment. Beforehand please do not suggest nor GCM neither Firebase as i am not interested in them and i will tell the reason after. So here is the scenario. I have a…
Volo Apps
  • 235
  • 1
  • 3
  • 12
4
votes
2 answers

Android broadcastreceiver not triggering when app is not running

Following this guide https://developer.android.com/training/monitoring-device-state/battery-monitoring.html I made a receiver that should log battery info to a file every time charger is plugged or unplugged. The activity reads the content of this…
Asalas77
  • 612
  • 4
  • 15
  • 26
4
votes
1 answer

Android BatteryManager.EXTRA_PLUGGED return AC

In Axon ZTE device, when I run the reciver private String isConnected(Context context) { String sRet = ""; try { final Intent mIntent = context.getApplicationContext().registerReceiver(null, new…
Eli Elezra
  • 525
  • 2
  • 4
  • 18
4
votes
4 answers

Android BatteryManager returning 0 for all property-retrieval calls

I'm having trouble trying to access most of the stats from my Android device's battery such as BATTERY_PROPERTY_CAPACITY, BATTERY_PROPERTY_CHARGE_COUNTER or BATTERY_PROPERTY_CURRENT_AVERAGE. These properties are all clearly documented here:…
Sergio Morales
  • 2,600
  • 6
  • 32
  • 40
3
votes
0 answers

Register contentObserver for Battery optimization changes

Since it's not possible to use the infamous action Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS to disable battery optimization in order to avoid sending the user to the settings screen to do so manually, I've tried to register an observer…
Lior Iluz
  • 26,213
  • 16
  • 65
  • 114
1
2 3
8 9