I have been trying to get this program to work but so far having no luck. I cannot find where I am doing wrong. I\'m not sure if there\'s something wrong with the code, or d
Also note that the Hangouts application will currently block my BroadcastReceiver from receiving SMS messages. I had to disable SMS functionality in the Hangouts application (Settings->SMS->Turn on SMS), before my SMS BroadcastReceived started getting fired.
Edit: It appears as though some applications will abortBroadcast() on the intent which will prevent other applications from receiving the intent. The solution is to increase the android:priority
attribute in the intent-filter
tag:
<receiver android:name="com.company.application.SMSBroadcastReceiver" >
<intent-filter android:priority="500">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
See more details here: Enabling SMS support in Hangouts 2.0 breaks the BroadcastReceiver of SMS_RECEIVED in my app
intent.getAction().equals(SMS_RECEIVED)
I have tried it out successfully.
Your broadcast receiver must specify android:exported="true"
to receive broadcasts created outside your own application. My broadcast receiver is defined in the manifest as follows:
<receiver
android:name=".IncomingSmsBroadcastReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
As noted below, exported="true" is the default, so you can omit this line. I've left it in so that the discussion comments make sense.
Stumbled across this today. For anyone coding an SMS receiver nowadays, use this code instead of the deprecated in OP:
SmsMessage[] msgs = Telephony.Sms.Intents.getMessagesFromIntent(intent);
SmsMessage smsMessage = msgs[0];