Detecting & sending SMS on Android 📮

Runtime permissions, BroadcastReceiver & SmsManger.


TL;DR: Project is available on GitHub. Note & Overview👇 gives you the rest.


1. Asking for permission

<!-- To use SMS based services -->
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
Sending SMS when you don’t ask for permissions in Marshmallow
Transport ETA requesting runtime SMS permission.
Showing a simple explanation beforehand

2. Sending SMS through our app

SmsManager.getDefault().sendTextMessage(number, null, smsText, null, null);

It’s considered good practice to inform the user normal fees apply, our app is just a dolled up version of the usual/default process. 💸

3. Listening for incoming SMS

Broadcast receiver that listens to incoming sms’s
private final String serviceProviderNumber;private final String serviceProviderSmsCondition;
smsBroadcastReceiver.setListener(new SmsBroadcastReceiver.Listener( {
public void onTextReceived(String text) {
// Do stuff with received text!
<receiver android:name="SmsBroadcastReceiver" />

While using BroadcastReceivers beware of the priority setting, (but don’t abuse it 🙌).


Hello! My name is Joaquim Ley, I’m currently based in Copenhagen, Denmark.

I create bugs on Android for a living. Besides coding and opensource, I ❤ photography & filmmaking.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store