read sms receive in your android app. SMS RECEIVER for android
 
In your manifest file, this entry must exist:-
<receiver
    android:name=".SmsReceiver"
    android:enabled="true"
    android:exported="true" >
</receiver>

permissions required are:-

<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />

public class SmsReceiver extends BroadcastReceiver {
     private final String TAG = this.getClass().getSimpleName();
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.e("on Received=",intent.getExtras().toString());
            Bundle data  = intent.getExtras();
            Object[] pdus = (Object[]) data.get("pdus");
            Log.e("SMS Received=",pdus.toString());
            double db_cr_amt=0;
            for(int i=0;ilength;i++){
                SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) pdus[i]);
                String sender = smsMessage.getDisplayOriginatingAddress();
                String messageBody = smsMessage.getMessageBody();
                Log.e("messageBody=",messageBody);
                //for amount (?i)(?:(?:RS|Rs|INR|inr|MRP|mrp).?s?)(d+(:?,d+)?(,d+)?(.d{1,2})?)
                //Pattern regEx=Pattern.compile("(?:inr|rs|Rs|INR|RS)+[s]*[0-9+[,]*+[0-9]*]+[.]*[0-9]+");
                //Pattern regEx=Pattern.compile("(?i)(?:(?:RS|Rs|INR|inr|MRP|mrp).?s?)(d+(:?,d+)?(,d+)?(.d{1,2})?)");
                 //below is pattern to get debit or credit amount sms from your bank, FI, etc.........
                Pattern regEx=Pattern.compile("(?i)(?:(?:RS|INR|MRP|Rs|inr|mrp|Inr).?s?)(d+(:?,d+)?(,d+)?(.d{1,2})?)");

                Matcher m=regEx.matcher(messageBody);

                if(m.find()) {
                    db_cr_amt=Double.valueOf(m.group(1));
                    Log.e(TAG,"amt="+db_cr_amt);
                }
                //number found after debited/debit with Rs./INR/etc
                  //date found after number founf
            }
            if(db_cr_amt>0) {
                Intent i = new Intent();
                //code to open your target activity// TODO::
                context.startActivity(i);
            }

        }

    }
share on whatapp
47 Views

Comments

 
 
Private Policy   Terms of Service   4922