Broadcast receiver is an android component that is used to response against system-wide broadcast events or messages like a battery getting low, receiving a SMS,WIFI detected , phone call received etc.
Broadcast Receivers do not have any user interface but you can generate the Android notification. With the help of broadcast receiver class we can catch Android operating system specific events and respond it with particular Android code.
Receiving Broadcasting Event
You can implement Broadcast receiver in two ways.The First one is to create a receiver class by extending BroadcastReceiver class and implement the onReceive Method.Then register it in Android manifest file.
public class MyReceiver extends BroadcastReceiver
{
public void onReceive(Context context, Intent intent) {
// Write a respond code over here
}
}
Register the Receiver Class
Then Register the Class in AndroidManifest.xml file
<receiver android:name="MyReceiver" >
<intent-filter>
<action android:name="ax.androidexample.mybroadcast" />
</intent-filter>
</receiver>
And the second way is to create a Object of Broadcast Receivers class at runtime and dynamically register the object.