Android - SMS Broadcast receiver
I tried your code and found it wasn't working.
I had to change
if (intent.getAction() == SMS_RECEIVED) {
to
if (intent.getAction().equals(SMS_RECEIVED)) {
Now it's working. It's just an issue with java checking equality.
android.provider.Telephony.SMS_RECEIVED
has a capital T
, and yours in the manifest does not.
Please bear in mind that this Intent
action is not documented.
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