• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Android 10 Issues: Battery BroadcastReceiver not working after update

mkm89

Lurker
Hello,

I made an app a while ago that uses a broadcast receiver to collect the battery level every time it changes using the "ACTION_BATTERY_CHANGED" intent. After updating my phone to Android 10, the receiver has stopped working. onReceive never occurs. Does anyone know what changed in the new update and how to fix it?

This is the significant portion of my code:

Code:
    private final IntentFilter batteryIntentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    private final BroadcastReceiver batteryReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context ctxt, Intent intent) {

            int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
            int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
        
        }
    };

The receiver is registered using:
registerReceiver(batteryReceiver, batteryIntentFilter);

I'd appreciate any help. Thanks!
 
Hello,
I have the same problem with my BroadcastReceiver which I use for Bluetooth discovery. Did you managed to solve your issue?
 
My issue was specific to OnePlus phones. There was a battery optimization feature in the new update called Intelligent Control that for some reason conflicted with my BroadcastReceiver. Hope that helps.
 
Thanks for your quick reply. Unfortunately, I am facing my problem on a Xiaomi Mi Mix 2S so apparently it is not related.
 
Back
Top Bottom