Receive the SMS class with the following code
For receive SMS private Smsreceiver msmsreceiver; @Override protected void Onresume () {super.onresume (); Msmsreceiver = new Smsreceiver (); Intentfilter intentfilter = new Intentfilter (); Intentfilter.addaction ("Android.provider.Telephony.SMS_RECEIVED"); Intentfilter.setpriority (1000); Registerreceiver (Msmsreceiver, Intentfilter); } @Override protected void OnPause () {super.onpause (); Unregisterreceiver (Msmsreceiver); } public class Smsreceiver extends Broadcastreceiver {public static final String sms_received_action = "Android . Provider. Telephony.sms_received "; @Override public void OnReceive (context context, Intent Intent) {String action = intent.getaction (); LOG.D (TAG, "action:" +action); if (Sms_received_action.equals (ACTION)) {Bundle bundle = Intent.getextras (); String messagecontent = bundle.getstring ("message"); Object[] PDUs = (object[]) bundle.get ("PDUs");//Get SMS array smsmessage[] messages = new Smsmessa Ge[pdus.length]; String format = Intent.getstringextra ("format"); for (int i = 0; i < messages.length; i++) {if (Build.VERSION.SDK_INT >= build.version_codes. M) {Messages[i] = SMSMESSAGE.CREATEFROMPDU ((byte[]) pdus[i],format);//convert PDU character array to Smsmessage object } else {Messages[i] = SMSMESSAGE.CREATEFROMPDU ((byte[]) pdus[i]) ; }} String address = Messages[0].getoriginatingaddress ();//Gets the number of the sender of the SMS string Fullmessage = ""; for (Smsmessage message:messages) {fullmessage + = Message.getmessagebody ();//Get SMS Content }//sender.settext (address); Content.settext (Fullmessage); LOG.D (TAG, "SMS NOTEs: "+fullmessage); Abortbroadcast (); } } }
Android SMS send and receive (ii)