The example of this article for everyone to share the Android mobile phone automatically get the message authentication code function for everyone to refer to, the specific content as follows
1. SMS Listening and broadcasting
2, read the message content
3, intercept the message content "can be reg interception"
4, fill out to the corresponding control
Ps:devstore test did not get the verification code
SOURCE Fragment
public class Mainactivity extends activity {private Broadcastreceiver smsreceiver;
Private Intentfilter Filter2;
Private Handler Handler;
Private EditText et;
Private String strcontent; Private String Patterncoder = "(?<!--\\d) \\d{6} (?!
\\d) ";
@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
ET = (edittext) Findviewbyid (r.id.et);
Handler = new Handler () {public void Handlemessage (Android.os.Message msg) {et.settext (strcontent);
};
};
Filter2 = new Intentfilter ();
Filter2.addaction ("Android.provider.Telephony.SMS_RECEIVED");
Filter2.setpriority (Integer.max_value); Smsreceiver = new Broadcastreceiver () {@Override public void onreceive (context context, Intent Intent) {OBJ
Ect[] Objs = (object[]) Intent.getextras (). Get ("PDUs");
for (Object Obj:objs) {byte[] PDU = (byte[]) obj; Smsmessage SMS = smsmessage.CREATEFROMPDU (PDU);
SMS content String message = Sms.getmessagebody ();
LOG.D ("logo", "message" + message); Short-term mobile phone number.
+86 opening?
String from = Sms.getoriginatingaddress ();
LOG.D ("logo", "from" + from);
Time is = 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)) {strcontent = code;
Handler.sendemptymessage (1);
}
}
}
}
};
Registerreceiver (Smsreceiver, Filter2);
} @Override protected void OnDestroy () {Super.ondestroy ();
Unregisterreceiver (Smsreceiver); /** * Matching 6 digits in the middle of the SMS (authentication code, etc.) * * @param patterncontent * @return/private String Patterncode (String pa Tterncontent) {if(Textutils.isempty (patterncontent))
{return null;
Pattern p = pattern.compile (Patterncoder);
Matcher Matcher = P.matcher (patterncontent);
if (Matcher.find ()) {return matcher.group ();
return null;
}}</pre-->
At the end of the article for everyone to share two topics for your reference:
"PHP Verification Code Encyclopedia"
The ASP. NET Authentication Code Encyclopedia "
The above is Android through the mobile phone to automatically obtain the text message verification Code of the detailed codes, I hope for everyone to achieve automatic access to mobile phone message verification code help.