Example of sending SMS verification code with mob for Android

The Internet competition with my roommate required an app, which involved the user's login and registration, so I found a lot of information on the Internet, including Alibaba cloud and Netease cloud. The customer service of Alibaba cloud told me that they didn't support Android, and Netease cloud had to take photos with ID cards. Both of them were charged and troublesome, so I found a simple and free one, It's called mob. The official website is as follows

Mob official website

After reading a lot of official documents, I still felt that they were not well written, so I wrote one myself.

Registered account

Click registration in the upper right corner of mob's official website and fill in the information in turn. You can fill in the company column freely

Add application

After logging in, click securitycodesdk - use now. Mob will prompt you to add an application. Fill in the name yourself, and then select Android. After adding, click securitycodesdk - to enter. After that, you should see the following interface

Appkey and appsecret will be used later

Download SDK

Click "free SMS verification code SDK" in the "download SDK" at the top of the web page. After the web page jumps, find the "SMS verification code SDK". Select the system as needed. I choose Android for Android. After the web page jumps, select Android studio or eclipse as needed. Select it on the right side of the screen. After selecting it, click to start downloading.

After downloading, unzip and open the folder. The directory structure is as follows

The SDK to be used is in the smssdk folder

Import SDK to project directory

Open the smssdk folder and copy the two. Jar and. AAR files to the LIBS folder in the project directory, as shown in the figure

After pasting in, select two. Jar files, right-click and select Add as library

Then open build.gradle under the app directory and add the following two contents

It looks like this in the end

Lines 22-26 and 36-37 were added.

Open androidmanifest.xml and add the following permissions

Program code

Paste the complete code first (if you don't paste XML, it doesn't affect it)

Be careful to replace your appkey and appsecret.

In fact, after reading many tutorials, you will find that most of the time, it is not that you can't understand the code, but that there is a problem in the configuration file. Because a person who has just been in contact with Android for two days can't have a demand for many third-party SDKs. At the beginning, they are mainly based on the foundation, so many people who need to configure third-party SDKs have written some Android code, What they care about is what methods should be called to achieve their goals, so just know how to call them, and then write a few if else according to the actual needs.

be careful

These lines of code are the basis for calling the SDK and are written in oncreate.

The statement to send SMS verification code is

The value of phonenumber depends on the number entered by the user. "86" is the area code of China. You can also choose it by yourself according to your needs. Just modify it a little.

These lines of code judge whether the verification code has been sent or not and whether it is correct. Determine the situation according to event. If you want to know more, you can refer to the official documents

Android sms sdk operation callback

Of course, the free service must be almost charged, which is reflected in that the SMS is sent slower than the charge. It takes about ten seconds to receive the charge, and it takes three seconds to receive the charge. Because it's just a game, playing by yourself is enough.

In addition, at the beginning, you can only send 20 text messages a day, and a mobile phone number can only receive 5 messages every 12 hours. Therefore, save some use. Of course, you can apply for online registration in the application management interface (see the first figure). After passing the audit, it will be completely free.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>