Android Auto-populated SMS verification code

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.