Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BroadcastReceiver + SMS_RECEIVED

Tags:

I'd like my app to catch incoming SMS messages. There are a few examples of this around. Looks like we just need to do this:

// AndroidManifest.xml <receiver android:name=".SMSReceiver">    <intent-filter>      <action android:name="android.provider.Telephony.SMS_RECEIVED" />    </intent-filter>  </receiver>          // SMSReceiver.java public class SMSReceiver extends BroadcastReceiver  {      @Override      public void onReceive(Context context, Intent intent) {          Log.i(TAG, "SMS received.");         ....     } } 

is this correct? I'm sending my phone some sms messages, but the log statement never gets printed. I do have some other SMS applications installed on the phone, which display a popup when the sms is received - are they somehow blocking the intent from getting passed down to my app, they are just consuming it completely?

Thanks

like image 854
Mark Avatar asked Dec 29 '09 05:12

Mark


People also ask

What is the use of BroadcastReceiver?

Android BroadcastReceiver is a dormant component of android that listens to system-wide broadcast events or intents. When any of these events occur it brings the application into action by either creating a status bar notification or performing a task.

What is a BroadcastReceiver in Android?

A broadcast receiver (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.

How do I check if BroadcastReceiver is registered?

Currently there is no way to check if a receiver is registered using the receiver reference. You have to unregister the receiver and catch the IllegalArgumentException that is thrown if it's not registered.

What is the method name in BroadcastReceiver receive the message?

To receive SMS messages, use the onReceive() method of the BroadcastReceiver class. The Android framework sends out system broadcasts of events such as receiving an SMS message, containing intents that are meant to be received using a BroadcastReceiver.


1 Answers

You would also need to specify a uses-permission in your manifest file:

<uses-permission android:name="android.permission.RECEIVE_SMS"/> 

The following tutorials should help:

React on incoming SMS
SMS messaging in Android

like image 162
Samuh Avatar answered Sep 23 '22 13:09

Samuh