Complete Android phone SMS verification source

Source: Internet
Author: User

SMS verification function I divide two modules, SMS verification code backstage and code to implement the function of SMS Verification code.

One, the background of SMS Verification code

1, Registered Mob account: Http://www.mob.com/#/login

2. After successful registration, click on "Avatar", Go to "Product Center", enter the following screen click the second item to add the app. Add the app after a few seconds and go to the second item again.

3. after the second step we will get two important parameters app key and app Secret, for the client and server link, after creating the application will also get two menu options "verification Record" and "SMS Settings", "Verification record" It means that after we do the SMS verification, the backstage will form a related record , such as the type of mobile phone, the carrier, the time of sending and the time of verification. "SMS Settings" is to say whether the current text messages support global operators, mainland operators and so on.

4, download the SDK, the specific how to download I will not say, I said to extract the various files of the SDK What do you mean , after decompression, we open apidoc-->index.html, we can see the content of this SDK. The contents of the inside are given a clear explanation. You can also look at the Smssdk folder, which contains the SDK source code. Inside there is a smssdk_user_guide, open after you can follow the steps inside the operation.

Third, the realization of SMS Verification code function

1. Import the SDK

If your SDK is Smssdk 2.0.1 After the save, after the download of the SDK decompression, I am the Android Studio SDK, so the following is done for Android studio. The following directory will appear:

Open the Smssdkmu directory and put the Mobcommons-2016.0303.1229.jar,mobtools-2016.0303.1229.jar,smssdk-2.0.2.aar inside, Smssdkgui-2.0.2.aar is placed in the Libs directory of the project app. Then in the app directory of the Build.gradle, plus the red circle of these words on the line.

2, configuration manifest file information, configuration content as follows:          

<--Permissions--
<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 "/><!--Configuring activity information--><activity Android:name=" Com.mob.tools.MobUIShell "android:configchanges=" Keyboardhidden|orientation|screensize "Android:them E= "@android: Style/theme.translucent.notitlebar" android:windowsoftinputmode= "Statehidden|adjustresize" >&Lt;/activity>

3. Initialize SDK:SMSSDK.initSDK (this, APPKEY, Appsecret);

4. Registered Mobile Number: registerpage registerpage = new Registerpage ();

5. Registration Callback Event          

Registerpage.setregistercallback (New EventHandler () {    ///event is completed after the call to public    void afterevent (int event, int result, Object data) {        //determine if the result has been completed        if (result = = Smssdk. Result_complete) {            @SuppressWarnings ("unchecked")            //Get Data             hashmap<string, object> phonemap = ( Hashmap<string, object>) data;            National information            String country = (string) phonemap.get ("Country");            Phone number information            String phone = (string) phonemap.get ("Phone");            Custom method Submission User Information            registeruser(country, phone);}        }    );

6. Display Registration Interface registerpage.show (mainactivity.this);

7, the RegisterUser method to explain

public void RegisterUser (string country,string phone) {        //randomly takes a number in the int type to be converted to a string random        r=new random ();        String uid= Math.Abs (R.nextint ()) + "";        String nickname= "CT";        Smssdk.submituserinfo (Uid,nickname,null,country,phone);    }

Iii. Results of operation

The above interface is self-built UI interface, click on the button above to start the above steps 5 and 6, will appear the following effect, the following UI is SMSSDK in the self-contained, do not need to build ourselves. The results are as follows:

  

Complete Android phone SMS verification source

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.