Broadcasting is a mechanism in which android will broadcast a message to all the apps. And apps should register for the particular broadcast message to receive it. This mechanism is used to notify all the system wide messages. Example of some predefined broadcast messages.
ACTION_BATTERY_CHANGED
ACTION_POWER_CONNECTED
ACTION_POWER_DISCONNECTED
ACTION_SHUTDOWN
see "Standard Broadcast Receiver Action" in Android Intent for more information.
Code snippet
----------- Broadcast receiver ------------------
class TestBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Action to be done on receiving the broadcast.
}
}
---------- Android Manifest xml -----------------
To use this TestBroadcastReceiver an entry should be made in Android Manifest xml file
--------Broadcast Sender ----------------
Intent intent = new Intent ("com.test.TEST_MESSAGE");
intent.sendBroadcast(intent);
No comments:
Post a Comment