difficulties encountered : No code was found to send the verification code to the mailbox directly on the client
solve the difficulty : did not find free to send mobile phone verification code interface, so intends to send a verification code in the mailbox, then a classmate told me to use the MoD can send free text messages, and then changed to send SMS verification code.
Steps:
1. The first step is, of course, a registered account
2. Click to enter the background → Select securitycodesdk→ Click to use → select app platform → get app key and app Secret
3. Download the SDK, after the decompression is like this:
4. Then install the website to import sdk[website link]http://wiki.mob.com/android-%e7%9f%ad%e4%bf%a1sdk%e9%9b%86%e6%88%90%e6%96%87%e6%a1%a3/
5. When configured, add permissions
6. I am here to customize the interface, of course, you can also use the system comes with the interface. Code calls:
//Initialize SMSSDK Private voidinitsdk () {smssdk.initsdk (Forgetpassword. This, "18e3768f516a3", "E05f202526cd41dcf17d2498d6a7aeeb"); EventHandler EventHandler=NewEventHandler () {@Override Public voidAfterevent (intEventintresult, Object data) {Message msg=NewMessage (); Msg.arg1=event; Msg.arg2=result; Msg.obj=data; Msg.what=Smsddk_handler; Handler.sendmessage (msg); } }; //Register callback Listener InterfaceSmssdk.registereventhandler (EventHandler); }Initializing the SDK
1Getnumber.setonclicklistener (NewView.onclicklistener () {2 @Override3 Public voidOnClick (View v) {4Userphone =Phonenumber.gettext (). toString ();5 NewAlertdialog.builder (Forgetpassword. This)6. Settitle ("Send SMS")7. Setmessage ("We will send the verification code to the following number: \ n" + "+ 86:" +Userphone)8. Setpositivebutton ("OK",NewDialoginterface.onclicklistener () {9 @OverrideTen Public voidOnClick (Dialoginterface Dialog,intwhich) { OneSmssdk.getverificationcode ("86", userphone); AGetnumber.setclickable (false); - NewThread (NewRunnable () { - @Override the Public voidrun () { - for(inti = 60; i > 0; i--) { - handler.sendemptymessage (code_ing); - if(I <= 0) { + Break; - } + Try { AThread.Sleep (1000); at}Catch(interruptedexception e) { - e.printstacktrace (); - } - } - handler.sendemptymessage (code_repeat); - } in }). Start (); - } to }) + . Create () - . Show (); the } *});Click to send verification code
Check.setonclicklistener (new View.onclicklistener () { @Override public void OnClick (View v) { smssdk.submitverificationcode ("Userphone", "Checknunber.gettext"). ToString ()); // callback function for verification of verification Code } });
Verify the verification code
Handler Handler =NewHandler () { Public voidhandlemessage (Message msg) {Switch(msg.what) { CaseCode_ing://sent, CountdownGetnumber.settext ("Resend (" +--time + "s)"); Break; CaseCode_repeat://re-sendGetnumber.settext ("Get Verification Code"); Getnumber.setclickable (true); Break; CaseSmsddk_handler:intevent =Msg.arg1; intresult =msg.arg2; Object Data=Msg.obj; //Callback Complete if(Result = =SMSSDK. Result_complete) {//Verification Code Verification successful if(Event = =SMSSDK. Event_submit_verification_code) {Toast.maketext (Forgetpassword. This, "Validation succeeded", Toast.length_long). Show (); } //The verification code has been sent Else if(Event = =SMSSDK. Event_get_verification_code) {Toast.maketext (Getapplicationcontext (), /c0>"Verification code has been sent", Toast.length_short). Show (); } Else{(throwable) data). Printstacktrace (); } } if(result==SMSSDK. Result_error) {Try{throwable throwable=(throwable) data; Throwable.printstacktrace (); Jsonobject Object=NewJsonobject (Throwable.getmessage ()); String des= object.optstring ("detail");//Error Description intStatus = Object.optint ("status");//Error code if(Status > 0 &&!)textutils.isempty (DES)) {Toast.maketext (Getapplicationcontext (), DES, Toast.length_short). Show (); return; } } Catch(Exception e) {//Do something } } Break; } } };callback function
Send phone verification code