Effective and minimal battery usage has to be performed by any app. An app would be able to do effective consumption of battery by determining the current charge status. Android has a class for determining the current battery status of the app. The BatteryManager broadcasts all battery and charging details in a sticky Intent that includes the charging status.
Using this battery manager, Zomato receives the charging status without registering a BroadcastReceiver by calling registerReceiver and passing in null as the receiver, as shown in the following code:
IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); Intent batteryStatus = context.registerReceiver(null, filter);
You'll be getting the batteryStatus intent, from which you can extract both the current charging status and if the device is being charged. It...