I have a broadcast receiver for ACTION_POWER_CONNECTED registered in manifest. When I connect power this is getting invoked and onReceive is working just fine.
In onReceive i am retrieving battery charging status using method given in google docs as follows:
IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = context.registerReceiver(null, ifilter);
int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
boolean isCharging = false;
if(status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL){
isCharging = true;
}
This method is giving me correct isCharging value for first time i connect the charger. When I unplug and again plug it back I am getting false for isCharging.
I am using Motorola XT1068 and facing above issue. The same code is working fine for One Plus Two.
Can someone please please guide me as I wanna make my app work in all phones thats why developing on min API 10.
From THIRD point in ans on (Detect Changing Battery state at every percentage in android) i also believe the same to be a problem. But I badly need a work around.
Thanks in advance. Edit:I know that as my receiver is registered for Battery Connected and hence there is no point in checking if its charging BUT i have other receivers which are not registered for this and still checks for battery status regularly.