---
title: "BroadcastReceiver in Android"  
description: "In this article I am explaining about BroadcastReceiver in Android"  
author: "Manoj Pandey"  
published: 2015-03-05  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/1633/broadcastreceiver-in-android  
category: "android"  
tags: ["android", "broadcast"]  
reading_time: 3 minutes  

---

# BroadcastReceiver in Android

A broadcast receiver is an Android component which allows you to register for system or application events. All registered receivers for an event are notified by the Android runtime once this event happens.

Broadcast intents are Intent objects that are broadcast via a call to the sendBroadcast(), sendStickyBroadcast() or sendOrderedBroadcast() methods of the Activity class (the latter being used when results are required from the broadcast). In addition to providing a messaging and event system between application components, broadcast intents are also used by the Android system to notify interested [applications](https://www.mindstick.com/articles/12847/how-to-choose-the-right-ethernet-cable-for-industrial-applications) about key system events (such as the external [power supply](https://answers.mindstick.com/qa/102408/describe-the-features-of-a-computer-power-supply-unit) or headphones being connected or [disconnected](https://www.mindstick.com/blog/300962/how-modern-life-disconnected-from-nature)).

Several system events are defined [as final](https://www.mindstick.com/interview/2388/can-you-declare-the-main-method-as-final-in-java) static fields in the Intent class. Other Android system classes also define events, e.g., the TelephonyManager defines events for the change of the phone state.

##### Intent.ACTION_BOOT_COMPLETED-:

Boot completed. Requires the android.permission.RECEIVE_BOOT_COMPLETED permission.

##### Intent.ACTION_POWER_CONNECTED-:

Power got connected to the device.

Intent.ACTION_POWER_DISCONNECTED-:

Power got disconnected to the device.

Intent.ACTION_BATTERY_LOW-:

Triggered on low battery. Typically used to reduce activities in [your app](https://answers.mindstick.com/qa/33368/how-will-you-design-a-listview-which-downloads-a-lot-of-images-and-displays-in-it-without-getting-your-app-hanged-whats-the-best-possible-way) which consume power.

Intent.ACTION_BATTERY_OKAY-:

Battery status good again.

Here is a sample which help you to clear the concepts of [BroadCastReceiver](https://www.mindstick.com/articles/1627/alarmmanager-with-broadcastreceiver-in-android) in Android

1. Create an Android project.

2. Create an IncommingCallReceiver class and extends with BroadcastReceiver , and add following code in this class

```
package com.example.callstatebroadcastreceiver; import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.telephony.TelephonyManager;import android.widget.Toast; public class IncommingCallReceiver extends BroadcastReceiver {     Context context;      @Override     public void onReceive(Context context, Intent intent) {           try {                String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);                // On InComing Call                if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {                     Toast.makeText(context, "Phone Is Ringing", Toast.LENGTH_LONG).show();                }                // On Dial call             if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {                     Text(context, "Call Recieved", Toast.LENGTH_LONG)                                .show();                }                // On cancel or disconnect call                if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) {           Toast.makeText(context, "Phone Is Idle", Toast.LENGTH_LONG)                                .show();                }           } catch (Exception e) {                           }     }}
```

3. Add permission and define receiver in Manifest.[xml file](https://www.mindstick.com/articles/75/how-to-read-and-write-xml-file-through-c-sharp)

```
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.callstatebroadcastreceiver"    android:versionCode="1"    android:versionName="1.0" >     <uses-sdk        android:minSdkVersion="8"        android:targetSdkVersion="17" />  <uses-permission android:name="android.permission.READ_PHONE_STATE" />     <application        android:allowBackup="true"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >        <activity    android:name="com.example.callstatebroadcastreceiver.MainActivity"            android:label="@string/app_name" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />           <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>         <receiver            android:name=".IncommingCallReceiver"            android:enabled="true" >            <intent-filter>           <action android:name="android.intent.action.PHONE_STATE" />            </intent-filter>        </receiver>    </application> </manifest>
```

4. No need to add extra code in MainActivity.class

```
package com.example.callstatebroadcastreceiver;import android.os.Bundle;import android.app.Activity;import android.view.Menu; public class MainActivity extends Activity {      @Override     protected void onCreate(Bundle savedInstanceState) {           super.onCreate(savedInstanceState);           setContentView(R.layout.activity_main);     }      @Override     public boolean onCreateOptionsMenu(Menu menu) {           // Inflate the menu; this adds items to the action bar if  // it is present.           getMenuInflater().inflate(R.menu.main, menu);           return true;     } 
```

Now run [your application](https://answers.mindstick.com/qa/95487/how-do-you-troubleshoot-when-your-application-link-is-not-responding) in [android device](https://www.mindstick.com/articles/342298/best-ways-to-customize-your-android-device-for-better-productivity)

On Incoming call

![BroadcastReceiver in Android](https://www.mindstick.com/mindstickarticle/adfe3356-d381-4c2a-b1b9-97f4205b084a/images/9e612cd9-4a2e-4135-b7af-e1ea09aaa40a.png)

On Dial call

![BroadcastReceiver in Android](https://www.mindstick.com/mindstickarticle/adfe3356-d381-4c2a-b1b9-97f4205b084a/images/1e1491b2-c005-4f2f-aab3-3661a668548d.png)

---

Original Source: https://www.mindstick.com/articles/1633/broadcastreceiver-in-android

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
