Method of integrating mob SMS verification code function in Android Development Project

1、 Foreword

Now apps basically need to use the SMS function. They need to send a SMS to users when registering or when there is a message notification. However, for individual developers, it is a bit extravagant to buy a third-party SMS service. The good thing is that mob provides us with a free SMS verification code service function. I don't advertise. I really think this service is very good. Now let's briefly talk about how to integrate the short message function of mob in our own project. In fact, the whole process is not complex. I just think the official documents of mob are a little messy, and the official demo is also a little complex. At the same time, some details are easy to be ignored, which will also lead to some problems. PS: I like mob's logo so much.

2、 Implementation process

This article only involves Android. If it is an IOS system, please consider it yourself. I hope this article can also help you. At the same time, the IDE is Android studio.

1. Key application

Application address: http://www.mob.com , select the SMS verification code SDK in the product center, and then complete the corresponding registration and application; Enter your own background center and you can see your own app key and app secret:

The overall trend bar shows us some usage of SMS services. If we don't register online, we can use 20 free SMS / day. If the demand is large, we can integrate mob SMS in our own project, and then register online. We should get more free SMS. We haven't tried yet.

2. Download SDK

Select SMS for Android in the SDK download column, and then select the SDK corresponding to the corresponding IDE (the ide in this article is as)

After downloading, it is like this:

3. Integration process

After applying for key and secret, they are integrated into their own projects. Mob mainly provides two interface modes: 1) use the official UI; 2) Use no GUI interface.

3.1. Configuring SDK

This is the old rule of using third-party interfaces. I won't post the official website documents. It really looks uncomfortable. I only post my own here.

First, add jar package and. AAR file under LIBS of the project.

Then add dependencies in build. Gradle

Add corresponding permissions and register corresponding activities in androidmanifest

3.2. Call the interface to send SMS

As mentioned earlier, the mob short message provides two methods with and without GUI. Either way, you need to initialize the smssdk first and then call the interface.

Initialization: smssdk.initsdk (loginactivity. This, "app key", "app secret");

1) There is a GUI, that is, using the interface provided by mob

The method is as follows:

2) No GUI

In this case, you usually use your own activity interface, and then integrate SMS functions, such as a simple registration.

OK, it's basically done.

3、 Question

Several problems may occur during integration:

1. Unable to receive SMS verification code

By default, the mob enables intelligent verification, which also means that if a number passes the verification code verification once, it will pass the intelligent verification when the SMS verification is performed again, and the verification code will not be received at this time, because the mob will not issue the verification code. This has a certain impact on our testing. Sometimes, we can't receive the verification code. That's why. Enter the background and turn off the intelligent verification function. Background Center - > SMS settings - > intelligent verification. Write a picture description here

2. After the SMS is verified successfully, the corresponding code is not executed, but returned to an interface

It is still possible that it is due to intelligent verification.

Therefore, the best way is to completely abandon the intelligent verification function.

The above is the whole content of this article. I hope it will help you learn Android Software Programming.

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
分享
二维码
< <上一篇
下一篇>>