Broadcast Receivers in android

    Broadcast Receivers in Android is also a component where you can register for system or application events. You will be notified of the events after registering.

There are following two important steps to make BroadcastReceiver works.

  1. Creating the Broadcast Receiver
  2. Registering Broadcast Receiver

Creating the Broadcast Receiver

     A broadcast receiver is implemented as a subclass of BroadcastReceiver class and overriding the onReceive() method where each message is received as an Intent object parameter.

public class MyReceiver extends BroadcastReceiver {
   public void
    onReceive(Context context, Intent intent) {
        Toast.makeText(context, "Intent Detected.",

Registering Broadcast Receiver

     An application listens for specific broadcast intents by registering a broadcast receiver in AndroidManifest.xml file.
<receiver android:name="MyReceiver">     
         <action android:name="android.intent.action.BOOT_COMPLETED"></action>
     There are several systems generated events defined as final static fields in the Intent class. The following table lists a few important system events.

android.intent.action.BATTERY_CHANGED – The sticky broadcast containing the charging state, level, and other information about the battery.
android.intent.action.BATTERY_LOW – Indicates low battery condition on the device.
android.intent.action.BATTERY_OKAY – Indicates the battery is now okay after being low.
android.intent.action.BOOT_COMPLETED- This is broadcast once after the system has finished booting.
android.intent.action.BUG_REPORT- Show activity for reporting a bug.
android.intent.action.CALL- Perform a call to someone specified by the data.
android.intent.action.CALL_BUTTON – The user pressed the “call” button to go to the dialer or other appropriate UI for placing a call.
android.intent.action.DATE_CHANGED – The date has changed.
android.intent.action.REBOOT – Have the device reboot.

Broadcast Receivers in Android Example

Here is my sample code using broadcast receiver with android.intent.action.PHONE_STATE to track phone incoming call status.

Register the broadcast receiver

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    android:versionName="1.0" >
        android:targetSdkVersion="15" />
        android:theme="@style/AppTheme" >
            android:label="@string/app_name" >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            android:enabled="true" >
                    <action android:name="android.intent.action.PHONE_STATE" />

Create broadcast receiver

public class IncomingcallReceiver extends BroadcastReceiver{ 
 Context context;  
                  public void onReceive(Context context, Intent intent){  
           String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);  
                   Toast.makeText(context, "Phone is ringing", Toast.LENGTH_LONG).show();  
                   Toast.makeText(context, "Call recieved", Toast.LENGTH_LONG).show();  
              if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)){  
                   Toast.makeText(context, "Phone is idle", Toast.LENGTH_LONG).show();  
          catch(Exception e){e.printStackTrace();}  

velmm download code

Leave a Reply

Your email address will not be published. Required fields are marked *