Android Broadcastreceiver Example Code Description

android-logoAndroid Broadcastreceiver Example:

Here we will learn the simplest way for how to use  Android broadcastreceiver using ‘Android Broadcastreceiver Example‘. It is very easy to use broadcastreceiver in Android. Here we will take an example for incoming SMS. We will register a broadcast receiver for incoming SMS. Then our application will receive notification when a new incoming SMS will come to the phone.
 That means we are going to discuss about incoming SMS listener using Android broadcastreceiver.

How to use Android Broadcastreceiver with Example

To make this example very simple, let’s take an example for incoming SMS. we will register the broadcast receiver for incoming SMS and receive the notification when a new SMS will come to our phone.  Using Android broadcast receiver is a 3 step process.

1. First Create your Receiver Class

First create your own Receiver class by extending from Android default BroadcastReceiver class. Then @Override the onReceive() method in your class. This onReceive() method will be called when a new SMS will come to the phone. Below is my Receiver Class for getting incoming SMS notification. In the onReceive() method we will get incoming SMS details. We will show the incoming SMS details using an Android Toast in our application.

 2. Register your Broadcastreceiver to Get Notification.

There are two different ways to register the broadcastreceiver in Android.

1. Register  the broadcastreceiver in your project’s Manifest file. If you will use this method then you can’t control the lifecycle of broadcast receiver. That means  your application will getting notification unless until you uninstall the application.

2. Register  the broadcastreceiver using Android’s Context.registerReceiver() method. By using this method, we can control it’s lifecycle by registering and un-registering broadcast receiver as per our requirement. To make this tutorial very simple, lets use Manifest process here, then we will go for Context.registerReceiver() method in a separate post.

So let’s register our own Receiver class with the incoming SMS intent filter in Manifest file. For incoming SMS example, my manifest file looks like below.

Complete Android Broadcastreceiver Example Manifest File

3. Add user permission for the broadcastreceiver.

Make sure to add user permissions for the broadcastreceiver. in my case (incoming SMS), i have added below permission in the above Manifest file.

That’s it. Once you install the application, at that time the broadcastreceiver will be automatically register with Android OS, and you will get notification as an Android Toast with details.


Download Android Broadcastreceiver Example from Here.

I hope this small tutorial on ‘Android broadcastreceiver example’ will help at it’s best.


Post By SmrutiRanjan (57 Posts)

Working @ Samsung as a Project Lead for Android Smartphones. I have been blogging since 2008. Previously I was writing articles for other bloggers, but finally I have started my own blog-"Techblogon".I am also an active contributor for the blog-"Gadgets n Gizmos World". Job is my necessity, but blogging is my passion.

Website: → Techblogon


4 Responses to Android Broadcastreceiver Example Code Description

  1. maillot de foot says:

    I am really thankful to the owner of this site who has shared this wonderful post at at this place.

  2. Rohan Satote says:

    above broadcast example is very nice, easy to understand BroadcastReceiver concept.

  3. Lawrence Maina says:

    Thanks for the tutorial, however I researched and tried so many examples but am yet to get means of capturing sent sms. Created a service that only works once, if the user switches to another application, the service stops working. I have registered it in the manifest. Actually the app shows that the srvice is running but it’s not working as expected.

  4. Dhina says:

    All the blocks are very well. It is very useful for me.

    what are the steps to follow the multiple-screen
    support application? and one more questions..

    Can you explain android Memory-Management and Inter Process Communication?

Leave a Reply

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

− 1 = four

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">