1. Are you ready for the Galaxy S20? Here is everything we know so far!

Android 10 Issues: Battery BroadcastReceiver not working after update

Discussion in 'Android Development' started by mkm89, Jan 1, 2020.

  1. mkm89

    mkm89 Lurker
    Thread Starter


    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 (Text):
    1.     private final IntentFilter batteryIntentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    2.     private final BroadcastReceiver batteryReceiver = new BroadcastReceiver() {
    4.         @Override
    5.         public void onReceive(Context ctxt, Intent intent) {
    7.             int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
    8.             int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
    10.         }
    11.     };
    The receiver is registered using:
    registerReceiver(batteryReceiver, batteryIntentFilter);

    I'd appreciate any help. Thanks!

    1. Download the Forums for Android™ app!


  2. AntonisK

    AntonisK Lurker

    I have the same problem with my BroadcastReceiver which I use for Bluetooth discovery. Did you managed to solve your issue?
  3. mkm89

    mkm89 Lurker
    Thread Starter

    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.
  4. AntonisK

    AntonisK Lurker

    Thanks for your quick reply. Unfortunately, I am facing my problem on a Xiaomi Mi Mix 2S so apparently it is not related.

Share This Page