The automatic interception of SMS is actually a broadcastreceiver that is registered in the system and then intercepted by setting up SMS:
Filter.addaction ("android.provider.Telephony.SMS_RECEIVED"); 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:
Smsreceiver =NewBroadcastreceiver () {@Override Public voidOnReceive (Context context, Intent Intent) {object[] Objs= (object[]) Intent.getextras ().Get("PDUs"); for(Object obj:objs) {byte[] PDU = (byte[]) obj; Smsmessage SMS=SMSMESSAGE.CREATEFROMPDU (PDU); String message=Sms.getmessagebody (); LOG.D ("SMS Content","message:"+message); //Short-interest mobile phone number. +86 opening? String from=sms.getoriginatingaddress (); LOG.D ("SMS Source","From :"+ from); //Time Time = new Time (); //Time.set (Sms.gettimestampmillis ()); //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)) {Message msg=NewMessage (); Msg.what=1; Bundle Bundle=NewBundle (); Bundle.putstring ("Messagecode", code); Msg.setdata (bundle); Handler.sendmessage (msg); } } } } };
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) ".
Android Auto-populated SMS verification code