The automatic interception of SMS is actually a broadcastreceiver that is registered in the system and then intercepted by setting up SMS:
1 Filter.addaction ("Android.provider.Telephony.SMS_RECEIVED"); 2 Filter.setpriority (Integer.max_value);
You can intercept the text messages you need, intercept SMS may need to set the latest time, this problem I also consider, the next step is to rewrite the Onrecever method:
1Smsreceiver =NewBroadcastreceiver () {2 @Override3 Public voidOnReceive (Context context, Intent Intent) {4Object[] Objs = (object[]) Intent.getextras (). Get ("PDUs");5 for(Object obj:objs) {6 byte[] PDU = (byte[]) obj;7Smsmessage SMS =SMSMESSAGE.CREATEFROMPDU (PDU);8String message =sms.getmessagebody ();9LOG.D ("Message content", "message:" +message);Ten //Short-interest mobile phone number. +86 opening? OneString from =sms.getoriginatingaddress (); ALOG.D ("SMS Source", "From:" +from ); - //Time Time = new Time (); - //Time.set (Sms.gettimestampmillis ()); the //String time2 = time.format3339 (true); - //log.d ("logo", from + "+ message +" + time2); - //strcontent = from + "" + Message; - //handler.sendemptymessage (1); + if(!Textutils.isempty (from)) { -String Code =patterncode (message); + if(!textutils.isempty (code)) { AMessage msg=NewMessage (); atMsg.what=1; -Bundle bundle=NewBundle (); -Bundle.putstring ("Messagecode", code); - Msg.setdata (bundle); - handler.sendmessage (msg); - } in } - } to } +};
Finally registered under Broadcastrecevier, notice how we capture the text message of the verification code, we certainly think of the interception of strings, but this way is more clumsy, I use the regular expression interception, String Patterncoder = "(? <!\\d) \\D{6} (?! \\d) ".
Auto-populate SMS. zip
Android Auto-populated SMS verification code