One-Tap SMS Verification in Android

Let’s continue our journey of building a seamless Android experience!

After we’ve done optimizing our hints in the first article, we can take the next step on our journey: One-Tap SMS Verification.

The Motivation

In the Bobobox Android app (our use case app), customers need to register themselves first with an email address or a phone number. If they use a phone number, they will need to input a One-Time Password (OTP) that will be sent to their number via SMS.

Take a look at the image below for the illustration.

In the most basic scenario, users that want to register via a phone number will have to open their SMS app (leave the Bobobox app), read the received OTP message, come back to theBobobox app, and then type in the OTP.

This is too many actions!

Plus, there is a chance that a user needs to switch between apps, which might seem trivial, but could impact your user’s experience on low-end devices.

One-Tap SMS Verification to the Rescue!

One-tap SMS verification (or SMS user consent API) is one of Google Identity’s features that allows your app to prompt the user to grant access to read the content of an SMS message that contains an OTP.

This is the perfect solution for our use case! With this feature, users don’t have to switch between apps and type in the OTP themselves.

How to Implement One-Tap SMS Verification?

Here are the steps needed to implement one-tap SMS verification in your app:

0. Add the below dependencies to your app/build.gradle file. Don’t forget to Sync your project afterwards.

1. Next, start the SMS User Consent API task like shown in the code snippet below. You can add this code inside your Activity’s onCreate. This piece of code will start a listener to incoming SMS messages that contain OTP (4–10 character alphanumeric with at least one number) for the next 5 minutes.

2. Next create a BroadcastReceiver that will receive the incoming SMS message. When OTP SMS message is received by the BroadcastReceiver, we need to launch a certain dialog for the user. This dialog will prompt the user to grant access to read the received SMS message. See the code snippet below for more details.

3. Finally, we need to declare the launcher for the dialog used in the previous step. The most important thing to notice here is how to get the content message of the SMS and how to parse the OTP from that message. And lastly, you need to set the value of your input with that OTP.

4. Aand you’re done! Once you put those together, you will have a functioning one-tap SMS verification like shown in the image below:

One-Tap SMS Verification in action. Once an SMS message containing OTP is received, the user is prompted to grant access to read that message. If the user clicks “Allow”, the OTP will be read directly and filled into the input. (Disclaimer: This is just a demonstration for this article and might not be representative of the real Bobobox app).

Do you Like this Article?

Leave us some claps 👏 and follow our Medium publication for more articles like this.

And don’t forget to download our app on your Android or iOS and book your first room in Bobobox! 😀

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store