Easy Ways To Implement Automatic Sms Verification In Android

sms verify

There are many ways to do the verification process in an Android application. As mobile developer, we know that one of the best way is using sms verification service. Since we all know most mobile phone users have a phone number for their phone.

But, input the code that we received from SMS is not user friendly. User has to view all the messages in the phone and see the code on it, then back again to the app to input the code. We, as mobile developer on mobile application deveopment, need "something" that can read those messages and get the code then fill in the field automatically.

Actually, there are many ways to automatically fill the OTP field by reading the message in our phone using READ_SMS permission. But, Google has strictly prohibited the usage of that permission for security purposes. You can read the full explanation here. If you want to find out extra information on sms verification service, you have to browse around here https://smsverification.xyz/ website.

Since we can't use the read SMS permission anymore, Google has given some other choices to implement automatic SMS verification using SMS Verification API which includes the automatic and one-tap SMS verification. Let's find out how they work and implement it in our mobile application development!

Automatic SMS Verification

The automatic SMS verification is the best way to do the sms verify. Because, users don't have to do any action and just wait until the verification process is complete. Also, it doesn't require any permission, but you have to make sure that you follow these criterias:

Messages that are sent to the user's device must be no longer than 140 bytes.

Message must contains a one-time code that user's will send back to the server.

Message must contain an 11-character hash string.

Now, let's implement automatic SMS verification in our app!

Prerequisites

This only works in Android devices with play service version 10.2 or latest.

Import Library

Import these libraries into your app's gradle to start using SMS Retriever API.

Obtain Phone Number

There are several ways to obtain a user's phone number. The best way that Google recommends is using a hint picker.

Start SMS Retriever

After you have got the user's phone number, then you are ready to start the SMS Retriever to listen to SMS that contains a unique string to identify your app for up to 5 minutes.

Send User's Phone Number to Server

Then, you should send the user's phone number to the server for triggering the verification process. The server will send an SMS containing the one-time code and a unique string to identify your app.

Receive Verification Message

When a client's phone receives any message containing a unique string, SMS Retriever API will broadcast the message with SmsRetriever.SMS_RETRIEVED_ACTION intent. Then, you should use a broadcast receiver to receive the verification message.

Send OTP Code Back to Your Server

After you got the message that contains one-time code, use some regex or other logic to extract your code from the message. Then, send that code back to the server.

One-tap SMS Verification

Up there, we have talked about how to do Automatic sms verify. It will help us as Android developer, for sure, on developing our mobile application. But then, there still another way from Google.

Views: 12

Comment

You need to be a member of On Feet Nation to add comments!

Join On Feet Nation

© 2024   Created by PH the vintage.   Powered by

Badges  |  Report an Issue  |  Terms of Service