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:
The receiver is registered using:
registerReceiver(batteryReceiver, batteryIntentFilter);
I'd appreciate any help. Thanks!
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!