java - How to Filter/Extract Code from SMS (Android) -


so i'm working on whatsapp verification system user inputs code received via sms , code sent server..yada yada ..all basic stuff.

my dilemma have received , read sms correctly. how filter body that passes number (not phone number verification code) edittext automatically. i'm trying avoid users having enter verification code manually. lemme show code below.

public void processreceive(context context, intent intent){      bundle bundle = intent.getextras();     if(bundle == null){         return;     }      object[] objectarray = (object[])bundle.get("pdus");      for(int = 0; < objectarray.length; i++){         smsmessage smsmsg = smsmessage.createfrompdu((byte[])objectarray[i]);         string smsbody = smsmsg.getmessagebody();          toast.maketext(context, smsbody, toast.length_short).show();     }  } 

//in code above, broadcastreceiver receives sms , can display body in toast. sms goes this: "your verification code: 12345".

how code sms , send value , edittext programmatically whatsapp does.

number = (edittext) findviewbyid(r.id.number); 

thank you. input appreciated

try may you

public static string general_otp_template = "your verification code: (.*).";  smsmessage[] message = new smsmessage[objectarray.length]; (int = 0; < objectarray.length; i++) {     message[i] = smsmessage.createfrompdu((byte[]) objectarray[i]);  } pattern generalotppattern = pattern.compile(general_otp_template); matcher generalotpmatcher = generalotppattern.matcher(message[0].getmessagebody().tostring());  if (generalotpmatcher.find()) {        string otp = generalotpmatcher.group(1);        number.settext(otp); } 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -