55.11 Listening for System Broadcasts
The final stage of this example is to modify the intent filter for the broadcast receiver to listen also for the system intent that is broadcast when external power is disconnected from the device. That action is android.intent.action.ACTION_POWER_DISCONNECTED. Modify the configureReceiver() method in the MainActivity.java file to add this additional filter:
private void configureReceiver() {
IntentFilter filter = new IntentFilter();
filter.addAction("com.ebookfrenzy.sendbroadcast");
filter.addAction(
"android.intent.action.ACTION_POWER_DISCONNECTED");
receiver = new MyReceiver();
registerReceiver(receiver, filter);
}
Since the onReceive() method in the MyReceiver.java file is now going to...