56.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 onCreate() 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 is now going to be listening for two types of broadcast...