Visit GitHub RepoMessaging

SMS Parser - Android

Receiving and Parsing SMS Messages on Android Devices

Build Status Download Android Arsenal API License Open Source Love


This module was created for getting specific codes out of incoming SMS messages. To use it you create a Config object where you specify the BEGIN and END message phrases & the SMS sender numbers from which you want to read the sms content. The received code then can be used according to your need (activation, authentication etc...).

How it Works

If you get a SMS message like this:

This is an automated message used by X-App. You can delete this message at any time.

and the sender of the message is one of the numbers you have specified in your Config object the parsing process will begin.

First the module reads the whole message. It then checks if it contains the BEGIN and END phrases you specified. If it does then it takes only the part that is between those phrases and send a broadcast to you app with the specific code and the sender phone number. In this case the module would send a broadcast containing 08ff08d3b2981eb6c611a385ffa4f865 and the sender number.

For more info read Usage.


Add the module to your apps build.gradle:

compile ''

First of all you have to create a Config object to configure the modules use:

                "0900123456", "0900654321", "0900900900");

Here the two parameters are the keywords that will be used for the code to be extracted from the sms message. The third parameter is a varargs (...) parameter, where you can give a series of phone numbers (as Strings), which will be checked against for reading sms content.

Then before startinganything you have to aks for the SMS Permmision on Android 6.0 and higher, or else the module won't work:

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

Then you need to create a LocalBroadcastManager and BroadcastReceiver, like this:

    private LocalBroadcastManager localBroadcastManager;

    private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(SmsReceiver.INTENT_ACTION_SMS)) {
                String receivedSender = intent.getStringExtra(SmsReceiver.KEY_SMS_SENDER);
                String receivedMessage = intent.getStringExtra(SmsReceiver.KEY_SMS_MESSAGE);
                        receivedSender != null ? receivedSender : "NO NUMBER"));
                        receivedMessage != null ? receivedMessage : "NO MESSAGE"));

LocalBroadcastManager is used instead of standard BroadcastManager for security reasons, so no other app can listen to the broadcasts that are sent.

You must create register and unregister methods for the BroadcastReceiver and call them in onResume() and onPause(), respectively:

    protected void onResume() {
    protected void onPause() {

    private void registerReceiver() {
        localBroadcastManager = LocalBroadcastManager.getInstance(Context);
        IntentFilter intentFilter = new IntentFilter();
        localBroadcastManager.registerReceiver(broadcastReceiver, intentFilter);

    private void unRegisterReceiver() {




Become a better Android Developer
Millions of developers are learning at MindOrks

Online Training Program

Featured Blogs

Our Team

MindOrks is Certainly one of the best online blog to stay on top of all the Android development news, coding and design patterns. Finally a blog I can count on to keep myself updated with latest and greatest things happening in Android world.

Vipul Shah
Android Developer

Become Pro in Android by watching videos