I just want to ask if anyone knows or have a working SMS receiver / handler code for android. Because I've been searching the net for days now and I still haven't seen an updated code, most seem to have deprecated codes on them like the one here http://mobiforge.com/developing/story/sms-messaging-android I would REALLY appreciate it if someone could teach me the new codes for receiving SMS in an application. thanks!
-
I am doing something similar HERE!!! http://stackoverflow.com/questions/14452808/sending-and-receiving-mms-in-android – Etienne Lawlor Jan 22 '13 at 08:15
3 Answers
I've just recently implemented a working BroadcastReceiver to handle SMS messages. The key parts are the manifest and the BroadcastReceiver.
In the manifest you need the RECEIVE_SMS permission:
<uses-permission android:name="android.permission.RECEIVE_SMS" />
You don't need READ_SMS. Your receiver entry should look something like this:
<receiver
android:name=".IncomingSmsBroadcastReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
The bit that most people seem to forget is android:exported="true"
which is required because the broadcast originates from outside your application. Some postings suggest you need android:permission="android.permission.RECEIVE_SMS"
or android:permission="android.permission.BROADCAST_SMS"
but this isn't the case.
My BroadcastReceiver implementation looks like this:
package smsmanager;
import java.util.List;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
public class IncomingSmsBroadcastReceiver extends BroadcastReceiver {
private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
@Override
public void onReceive(final Context context, final Intent intent) {
if (intent != null && SMS_RECEIVED.equals(intent.getAction())) {
final SmsMessage smsMessage = extractSmsMessage(intent);
processMessage(context, smsMessage);
}
}
private SmsMessage extractSmsMessage(final Intent intent) {
final Bundle pudsBundle = intent.getExtras();
final Object[] pdus = (Object[]) pudsBundle.get("pdus");
final SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) pdus[0]);
return smsMessage;
}
private void processMessage(final Context context, final SmsMessage smsMessage) {
// Do something interesting here
}
}
And everything works just as I want it to, and I can stop burning up my SMS allowance testing ths

- 4,522
- 1
- 25
- 29
-
The Google administrators for the Google Play Store consider the RECEIVE_SMS permission to be dangerous. As a result, an app that contains the permission will be rejected. Then the developer has to submit a form to Google Play administrators for approval. Other developers have mentioned the process is awful with feedback taking weeks, receiving only general feedback and often outright rejections are received with no explanations. Any ideas on how to avoid? – AJW Jul 15 '20 at 14:50
-
You appreciate that you're commenting on a post from eight years ago, right? I totally get what you're saying, today, and don't disagree - I even logged a feature request around it - https://issuetracker.google.com/u/2/issues/36938591 - which was ignored and then closed in '14. But back in '12 people, me included, were writing alternative SMS clients and all sorts. – Phil Haigh Jul 17 '20 at 12:15
-
But no, I'm not aware of an easy way to avoid this issue. Bottom line, bad actors were abusing the availability of SMS related intents to intercept and forward messages. You need a very convincing case to be approved, and that's as it should be. There are very few reasons for sending or receiving text messages outside of a messaging app. – Phil Haigh Jul 17 '20 at 12:19
This Should work, and is not deprecated, if you replace android.telephony.gsm.SmsMessage
with android.telephony.SmsMessage
. it's just about listening for android.provider.Telephony.SMS_RECEIVE
.

- 5,402
- 1
- 27
- 40
-
The Google administrators for the Google Play Store consider the RECEIVE_SMS permission to be dangerous. As a result, an app that contains the permission will be rejected. Then the developer has to submit a form to Google Play administrators for approval. Other developers have mentioned the process is awful with feedback taking weeks, receiving only general feedback and often outright rejections are received with no explanations. Any ideas on how to avoid? – AJW Jul 15 '20 at 14:52
There is a thread here which includes code to do what you're asking for. Note that there are some corrections in the answers there.

- 1
- 1

- 375
- 2
- 8