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

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

    I'd appreciate any help. Thanks!
     

    Advertisement

Loading...
Similar Threads - Android Issues Battery
  1. Hari Venkatesh
    Replies:
    1
    Views:
    349
  2. Gerie
    Replies:
    4
    Views:
    274
  3. ragekage23424
    Replies:
    0
    Views:
    424
  4. Naveed Qureshi
    Replies:
    2
    Views:
    1,522
  5. CHOPPERBUM
    Replies:
    4
    Views:
    1,520
  6. jmd494
    Replies:
    3
    Views:
    786
  7. DarkLightHitomi
    Replies:
    1
    Views:
    214
  8. sreekar1998
    Replies:
    1
    Views:
    250
  9. phantomsdad
    Replies:
    5
    Views:
    237
  10. JolieBeth23
    Replies:
    5
    Views:
    779

Share This Page

Loading...