Android Open Source - smsFwd S M S Receiver






From Project

Back to project page smsFwd.

License

The source code is released under:

Icon is combined from https://github.com/google/material-design-icons

If you think the Android project smsFwd listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.lanky.smsforward;
//from   w  ww  . java 2s .com
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.provider.Telephony;
import android.telephony.SmsMessage;

public class SMSReceiver extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {
    SmsMessage[] sms_messages = Telephony.Sms.Intents.getMessagesFromIntent(intent);
    //Log.e("smsfwd", "SMS length: " + sms_messages.length);
    String message_sender = "";
    String sms_message_body = "";

    for (SmsMessage message : sms_messages) {
      message_sender = message.getOriginatingAddress();
      // String message_body = message.getMessageBody();
      sms_message_body = sms_message_body + message.getMessageBody();
    }

    if (sms_message_body != null) {
      sms_message_body = "[" + message_sender + "]" + sms_message_body;
      //Log.e("smsfwd", sms_message_body);
      MainActivity.onReceivedSMS(context, sms_message_body);

    }
  }
}




Java Source Code List

com.lanky.smsforward.MainActivity.java
com.lanky.smsforward.SMSReceiver.java