Receiving SMS Using BroadcastReceiver and Intent

Receiving SMS Using BroadcastReceiver and Intent

The following sample program describes how to Receive SMS using broadcast receiver with Intent

Step 1
Create broadcast receiver class for receiving SMS.

import android.content.*;
import android.os.Bundle;
import android.telephony.*;
import android.util.Log;
import android.widget.Toast;

public class SimpleSmsReciever extends BroadcastReceiver {

 private static final String TAG = "Message recieved";

 public void onReceive(Context context, Intent intent) {    
     Bundle pudsBundle = intent.getExtras();
     Object[] pdus = (Object[]) pudsBundle.get("pdus");
     SmsMessage messages =SmsMessage.createFromPdu((byte[]) pdus[0]);    
     Log.i(TAG,  messages.getMessageBody());
     Toast.makeText(context, "SMS Received : "+messages.getMessageBody(),


Step 2
Configure the AndroidManifest.xml file

<?xml version="1.0" encoding="utf-8"?>
<manifest android="" 
package="" versioncode="1" versionname="1.0">
 <application icon="@drawable/icon" label="@string/app_name">
     <receiver name=".SimpleSmsReciever">
             <action name="android.provider.Telephony.SMS_RECEIVED">
 <uses-sdk minsdkversion="6">
 <uses-permission name="android.permission.INTERNET">


Leave a Reply

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