This article explains the Android automatic extraction of SMS Authentication code solutions, shared for everyone to refer to, the specific content as follows
<uses-permission android:name= "Android.permission.RECEIVE_SMS" ></uses-permission>
< Uses-permission android:name= "Android.permission.READ_SMS" ></uses-permission>
Package Com.dongdongsongcan.app;
Import Android.content.BroadcastReceiver;
Import Android.content.Context;
Import android.content.Intent;
Import Android.telephony.SmsMessage;
Import Com.su.dolphin.utils.LogUtil;
Import java.util.ArrayList;
Import java.util.List;
Import Java.util.regex.Matcher;
Import Java.util.regex.Pattern; public class Smsreceiver extends Broadcastreceiver {public interface Ismslistener {public void onsmsreceive (St
Ring verifycode);
private static Ismslistener Msmslistener;
Public Smsreceiver (Ismslistener ismslistener) {msmslistener = Ismslistener;
public static final String TAG = "Imichatsmsreceiver"; Android.provider.Telephony.Sms.Intents public static final String sms_received_action = "Android.provider.Telephony
. sms_received "; @Override public void OnReceive (context context, Intent Intent) {LOGUTIL.D (">>>>>>>>& Gt;>>>>>>>>>>>>>&gT;>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>> ");
if (Intent.getaction (). Equals (Sms_received_action)) {smsmessage[] messages = getmessagesfromintent (intent);
for (Smsmessage message:messages) {//LOGUTIL.D (message.getoriginatingaddress () + ":" +//
Message.getdisplayoriginatingaddress () + ":" +////Message.getdisplaymessagebody () + ":" +
Message.gettimestampmillis ());
String msg = Message.getdisplaymessagebody ();
LOGUTIL.D ("msg:" + msg);
String verifycode = null;
Pattern p = pattern.compile ("\\d{4}");
Matcher m = p.matcher (msg);
while (M.find ()) {Verifycode = M.group ();
Break
} logutil.d ("Verifycode" + Verifycode);
if (Msmslistener!= null) {msmslistener.onsmsreceive (Verifycode);
} }} public final smsmessage[] Getmessagesfromintent (Intent Intent) {object[] messages =
(object[]) Intent.getserializableextra ("PDUs");
byte[][] Pduobjs = new byte[messages.length][];
for (int i = 0; i < messages.length i++) {pduobjs[i] = (byte[)) messages[i];
} byte[][] PDUs = new byte[pduobjs.length][];
int pducount = Pdus.length;
smsmessage[] msgs = new Smsmessage[pducount];
for (int i = 0; i < Pducount i++) {pdus[i] = pduobjs[i];
Msgs[i] = SMSMESSAGE.CREATEFROMPDU (Pdus[i]);
return msgs;
}
}
The above is the entire content of this article, I hope to help you learn.