Android development belongs to your SMS verification Code (a)

Source: Internet
Author: User

Do not fly, soar, blockbuster---------Sima Qian


recent work and new requirements, require users to register at the time of the need to pass the phone verification code, so that the purpose is to prevent users through a mailbox to random registration, so good, today we come together to learn about the Android SMS verification code this knowledge point. If there is falsehood, welcome to criticize, if you have any questions welcome message, thank you


Before we talk about this knowledge, let's start by understanding the aggregated data.

I. Introduction of aggregated data

Aggregated data is one of the largest basic data API providers in China, specializing in Internet Data Services. Free to provide safe, stable and efficient data from weather inquiries, air quality, map coordinates to financial funds, e-commerce parity, illegal inquiries and other fields. Developers can free to try the aggregation data API for mobile app rapid development, eliminate data collection, maintenance and other links, greatly reduce development cycle and cost. So we can use aggregated data to provide me with a good set of things to do the function of SMS Verification code to add.

First of all, we have to prepare for the use of aggregated data mainly divided into the following steps:

The first step is to register an account with the aggregated data website.

After completing the registration, enter, "Personal Center"-click on the application data as shown


Enter your phone number, then you will receive the verification code, enter the verification code you received in the CAPTCHA click Request

The second step, after the application you will see a appkey, if you have already applied, you can follow the steps below to view your application Appkey

1. Go to the Personal center and click on my data as shown in



2. We click the View button and we will see the appkey of our application, so this appkey is very important .



The above two steps have already completed the Appkey application then we take the third step, download the SMS Verification Code SDK

Step three download SMS Verification Code SDK

1. Enter the home click Data Interface as shown




2. Locate the SDK center in the left-hand category as shown in



3. Click the SMS Verification Code SDK to enter the interface as shown


Here we have to download the SDK, we should enter the fourth step, create a project configuration environment

Fourth step, create the project, configure the environment

1. Create a project to copy the "Armeabi file" and "Smscaptcha_v_1_4.jar" under the Libs in our downloaded SDK to the Libs directory of our Project

2. Add the development key, required permissions, and other information in Androidmanifest

(1) in Application add a development key in

  <meta-data          android:name= "Juhe_key"          android:value= "developer KEY"/>

(2) Add the required permissions

<uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE"/>  <uses-permission android: Name= "Android.permission.INTERNET"/>  <uses-permission android:name= "android.permission.ACCESS_WIFI_ State "/>  <uses-permission android:name=" Android.permission.ACCESS_COARSE_LOCATION "/>  < Uses-permission android:name= "Android.permission.READ_FINE_LOCATION"/><uses-permission android:name= " Android.permission.READ_PHONE_STATE "/><uses-permission android:name=" Android.permission.READ_CONTACTS "/ >
(3)initializing the Context global variables referenced by the SDK when the application is created

In this step we have two ways

The first is configured in activity

public class Mainactivity extends Activity {      @Override      protected void onCreate (Bundle savedinstancestate) {          super.oncreate (savedinstancestate);           Initialize the context information before using each component of the SDK, pass in ApplicationContext          //Note that the method implements  /** * Initialization method before Setcontentview method * @param context * @needFriends need buddy function *         /commonfun.initialize (Getapplicationcontext (), true);          Setcontentview (R.layout.activity_main);      }  }

The following note is a suggestion for aggregating data documents, which suggests that we put this initialization work in application because the program runs first in the application method

Note: before each functional component of the SDK is used, you need to call commonfun.initialize (Getapplicationcontext (), true); , we recommend that the method be placed in the initialization method of the application

So we're going to do it the way it suggests, instead of using the first method so we need to create a Applicaiton class MyApplication as follows

Package Com.example.android.sms;import Com.thinkland.sdk.util.commonfun;import Android.app.application;public Class MyApplication extends application {@Overridepublic void OnCreate () {super.oncreate (); Commonfun.initialize (Getapplicationcontext (), false); }}

Do not forget to configure the manifest file after declaring the application



Okay, the environment is already configured, so let's check to see if we can get a message.

The code for Mainactivity is as follows

Package Com.example.android.sms;import Com.thinkland.sdk.sms.smscaptcha;import Com.thinkland.sdk.util.BaseData; Import Com.thinkland.sdk.util.commonfun;import Android.os.bundle;import Android.app.activity;import Android.util.log;import Android.view.menu;import Android.widget.toast;public class Mainactivity extends Activity { Protected static final String TAG = "mainactivity"; @Overrideprotected void OnCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main);//initialization  Smscaptcha object in this object has to send us the method of SMS Verification Code Smscaptcha smscaptcha=smscaptcha.getinstance ();//Call the method of sending SMS verification code, in which there is a callback/** Phone number callback Returns the result callback method. */smscaptcha.sendcaptcha ("Enter your phone number here", New Basedata.resultcallback () {@Overridepublic void onresult (int code, String Reason, String result) {/* Code: Return code: Server: 0 succeeded; 1 error; Local:-2 local network exception;-3 server network exception;-4 parsing error;-5 initialization exception Reason: Return information success or cause of error. Res Ult: Returns the result, in JSON format. Empty when error or no return value. */if (code==0) {log.i (TAG, "code=" +code); LOG.I (TAG, "reason=" +reason); LOG.I (TAG, "result=" +result);}});}} 


The returned results are as follows:


And the phone received a text message, OK, this one here, this is mainly the environment, the next article on the interface with you to discuss the implementation of UI, and verify that the input verification code is the correct verification code.



Android development belongs to your SMS verification Code (a)

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.