Reprint Please specify residence: http://blog.csdn.net/crazy1235/article/details/41912003
Introduced
SMS Verification feature Everyone is very familiar with it. Can be seen in a lot of places, new users or short-term verification payment. SMS verification uses SMS verification code to register members. This significantly reduces the illegal registration and greatly improves the security of the user account.
Now there are a lot of service providers that provide SMS verification, there is a charge. There are also free of charge.
The assumption is personal developers, with free is the most cost-effective! Below I will introduce a free SMS verification platform---mob.com
The SMS verification feature provided by the mob platform enables high-speed authentication and matching contacts with friends, and provides 10,000 free SMS verification per app daily. A lot of developers want to integrate the SMS verification function in their own app, let's experience the free "pleasure" below.
Application
1. First, you need to register as a mob platform user. Then go to the "Free SMS Verification Code SDK" in the control center. Click on "Add New app" on the interface to join your app. Once this step is complete, you will be provided with a AppKey and an App Secret. These two codes need to be written down, and the following are of great use.
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvy3jhenkxmjm1/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">
2. Open URL http://sms.mob.com/Download) to download the SDK. After decompression for example with:
smssdk is the Sdk,sample directory of the platform-provided authentication SMS is a demo.
3. Import this SDK in Ecliplse as a library. Then introduce it as a library into your own project.
Next, you need to include the following permissions in Androidmanifest.xml such as SMSSDK:
<uses-permission android:name= "Android.permission.READ_CONTACTS"/><uses-permission android:name= " Android.permission.READ_PHONE_STATE "/><uses-permission android:name=" android.permission.WRITE_EXTERNAL_ STORAGE "/><uses-permission android:name=" Android.permission.ACCESS_NETWORK_STATE "/><uses-permission Android:name= "Android.permission.ACCESS_WIFI_STATE"/><uses-permission android:name= " Android.permission.INTERNET "/><uses-permission android:name=" Android.permission.RECEIVE_SMS "/>< Uses-permission android:name= "Android.permission.GET_TASKS"/><uses-permission android:name= " Android.permission.ACCESS_FINE_LOCATION "/>
add information such as the following in the Activity tab:
<activityandroid:name= "Cn.smssdk.SMSSDKUIShell" android:configchanges= "keyboardhidden|orientation|screensize "Android:theme=" @android: Style/theme.translucent.notitlebar "android:windowsoftinputmode=" stateHidden| Adjustresize "/>
Next, when your project starts. Called
SMSSDK.INITSDK (This, "Appkey", "Appsecret");
The second and third parameters are the two codes you have added to the app on the mob platform!
Then join the register callback listener interface
Smssdk.regeistereventhandler (EventHandler);
among them EventHandler means destroying the function. Consists of four methods.
public void Onregister ();//Called when the callback object is being registered
public void Beforeevent (int event, Object data);//triggered before operation
public void Afterevent (int event, int result, Object data)//is triggered at the end of the operation
public void Onunregister ();//triggered at the time of the counter-register
in general, it is sufficient to implement the Afterevent method only. The method has 3 parameters, and the event represents the type of operation. Result indicates the outcome of the operation, and data represents the return of the operation.
The more frequently used EVENT has Event_get_verification_code (get verification Code), Event_submit_verification_code (submit verification code).
After processing is complete. Need to call back to destroy it
Smssdk.unresigtereventhandler (EventHandler);
Note: None of the four callback functions of EventHandler can be executed in the UI thread. You need to use handler to send messages to the UI thread.
Here's a look at my example:
/** * Initialize SMS SDK */private void Initsdk () {SMSSDK.INITSDK (this, "xxxxxx", "xxxxxxxx"); EventHandler EventHandler = new EventHandler () {/** * is triggered after operation * * @param event * Number 1 * @param result * Number of SMSSDK 2. Result_complete indicates that the operation was successful for SMSSDK. * Result_error indicates operation failed * result of @param data * Event operation */@Overridepublic void afterevent (int event, int result , Object data) {message msg = new Message (); msg.arg1 = Event;msg.arg2 = Result;msg.obj = Data;handler.sendmessage (msg);}} ;//Register Callback Listener Interface Smssdk.registereventhandler (EventHandler);}
@Overridepublic void OnClick (View v) {String phonenums = Phonenumet.gettext (). toString (); switch (V.getid ()) {case R.id.back_iv:this.finish (); Keyboardutils.closekeybord (Phonenumet, registeractivity.this); Break;case r.id.request_code_btn://1. Infer the phone number if (!judgephonenums (phonenums)) {return;}//2 through the rules. Send SMS verification via SDK ("Smssdk.getverificationcode", phonenums);//3. Turn the button into non-clickable and display a countdown (getting) requestcodebtn.setclickable (false), Requestcodebtn.settext ("Send Again (" + i--+ ")"); new Thread (New Runnable () {@Overridepublic void Run () {for (int i = +; i > 0; i--) {handler.sendemptymessage ( -9); if (i < ; = 0) {break;} try {thread.sleep;} catch (Interruptedexception e) {e.printstacktrace ()}} Handler.sendemptymessage (-8);}}). Start ();//4. Open the broadcast to receive read SMS Break;case r.id.commit_btn://judgephonenums (phonenums); Smssdk.submitverificationcode ("n", Phonenums, Inputcodeet.gettext (). toString ()); Createprogressbar ();//after validation passed. Write-off of the SMSSDK registration code//Smssdk.unregistereventhandler (EventHandler); Break;case R.id.clear_phone_Iv:phoneNumEt.setText (""); Break;case r.id.clear_code_iv:inputcodeet.settext (""); break;}}
Handler Handler = new Handler () {public void Handlemessage (Message msg) {if (Msg.what = = -9) {requestcodebtn.settext ("Send Again (" + I - + ")");} else if (msg.what = = -8) {Requestcodebtn.settext ("Get Verification Code"); Requestcodebtn.setclickable (true);} else {int event = Msg.arg1 ; int result = Msg.arg2;object data = msg.obj; LOG.E ("event", "event=" + event); if (result = = Smssdk. Result_complete) {//SMS after successful. Return to Mainactivity, and then prompt for new friend if (event = = Smssdk. Event_submit_verification_code) {//Submit Verification Code Success Toast.maketext (Getapplicationcontext (), "Commit verification code succeeded", Toast.length_short). Show (); Intent Intent = new Intent (registeractivity.this,mainactivity.class); startactivity (Intent);} else if (event = = Smssdk. Event_get_verification_code) {Toast.maketext (Getapplicationcontext (), "Authenticode sent", Toast.length_short). Show ();} else {((throwable) data). Printstacktrace ();}}}};
@Overrideprotected void OnDestroy () {Super.ondestroy ();//this.unregisterreceiver (Smsbroadcastreceiver); Smssdk.unregisteralleventhandler ();}
Summary At this point, a text verification function has been implemented. The platform has some limitations and the app must be networked. The verification code can only be 4 bits. There is the verification text message can not be defined, only can be "XXXX" XXXX Verification code: 7521. In such a form. If developers don't want to have these limitations, I think they can only work with operators. Download demo!
Free SMS verification of Android from zero single row