قالب وردپرس درنا توس
Home / IOS Development / Automatically implement SMS verification while developing an e-commerce app

Automatically implement SMS verification while developing an e-commerce app



If you are an entrepreneur or startup wanting to create your own Android mobile app with SMS verification feature, this development of the Android app will help you include SMS verification feature in the mobile app development project.

In this Android app training, we have split step by step process to implement automatic SMS verification using the SMS Retriever API in Android mobile app. First, we first need to understand what is the SMS verification process?

What is the SMS verification process?

Earlier, when users had to log in to the e-commerce or finance or shopping-related app on the Android platform, they had to enter the mobile number to receive an OTP. Then they had to copy the confirmation code received via SMS, return to the app and enter that code to log in.

To overcome this tedious process, Google introduced the message center functionality to automatically retrieve a verification code sent via SMS in an app.

The purpose of creating this SMS verification demo is to allow an Android app to detect and verify a verification code sent on a user's smartphone using the SMS Retriever API. It is useful to retrieve the verification code directly from the mobile phone.

After Google introduced an automatic SMS verification feature, they found some cases of mobile data access. Using the SMS verification feature, some Android apps got unauthorized access to the user's call logs and SMS logs. Due to this critical data security issue, Google must leave the feature for a while.

So, to provide the same functionality in a very safe way; Recently, Google has made some important changes to its policy by restricting access permissions. Now android users will choose which app they will allow to access their call logs or SMS logs. In this way, the apps authorized to access logs can send OTP to the mobile phone and automatically verify it with the SMS Retriever API. Thus, the user does not require manual copying and entering the code each time. So let's follow these steps to implement the code in an Android app.

Step: 1

Add the add-on to the app level Gradle file:

  implementation & # 39; com.google.android.gms: gaming services -auth: 16.0.1 & # 39;
implementation & com; com.google.android.gms: play-services-auth-api-phone: 16.0.0 & # 39;


Step: 2

Add SMS recipient broadcast in AndroidMenifest.xml file

Register SMS retrieval broadcast

 
 


 


Step: 3

Start SMS recipient activity to start the request for OTP

  selection client = SmsRetriever.getClient (this)
fall task = client.startSmsRetriever ()
task.addOnSuccessListener {
tvOtp.text = "Waiting for OTP"
Toast.makeText (this, "SMS Retriever starts", Toast.LENGTH_LONG) .show ()
}

task.addOnFailureListener {
tvOtp.text = "Cannot start SMS Retriever"
Toast.makeText (this, "Error", Toast.LENGTH_LONG) .show ()
}


Step: 4

Get SMS format and verification code in MySMSBroadcastReceiver

  class MySMSBroadcastReceiver: BroadcastReceiver () {

private was otpReceiveInterface: OTPReceiveInterface? = zero

funny setOnOtpListeners (otpReceiveInterface: OTPReceiveInterface) {
this.otpReceiveInterface = otpReceiveInterface
}

override fun at Receive (context: context ?, purpose: Intent?) {
if (SmsRetriever.SMS_RETRIEVED_ACTION == intent?. reaction) {
Selection extras = intent.extras
choice status = extras !!. get (SmsRetriever.EXTRA_STATUS) as Status

when (status.statusCode) {
CommonStatusCodes.SUCCESS -> {
was otp: String = extras.get (SmsRetriever.EXTRA_SMS_MESSAGE) as strict

if (otpReceiveInterface! = null) {

otp = otp.replace ("<#> Your otp code is:", "") .split ("n" .toRegex ()) dropLastWhile {it.isEmpty ()} .toTypedArray () [0]
// otp = otp.replace ("<#> Your otp code is:", "")
// You can filter OTP here and submit for activity}
}

CommonStatusCodes.TIMEOUT ->
if (otpReceiveInterface! = null) {
// SMS backlink timeout you can alert activity for same}
}

}
}

Now

if you want to use hintRequestIntent to retrieve the user's contact number from the phone, then:

Step: 1

  setup googleApiClient

// seen google api client for hint request
mGoogleApiClient = GoogleApiClient.Builder (this)
.addConnectionCallbacks (this)
.enableAutoManage (this, this)
.addApi (Auth.CREDENTIALS_API)
.build()


Step: 2

Request for numberHin by calling this method:

  // get available number in user phone
private fun getHintPhoneNumber () {
selection hintRequest = HintRequest.Builder ()
.setPhoneNumberIdentifierSupported (true)
.build()
choice intent = Auth.CredentialsApi.getHintPickerIntent (
mGoogleApiClient, hintRequest
)
startIntentSenderForResult (intent.intentSender, RESOLVE_HINT, zero, 0, 0, 0)
}


Step: 3

get the selected number in onActivityResult as:

  override fun onActivityResult (requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult (requestCode, resultCode, data)

// Result if we want hint number
if (requestCode == RESOLVE_HINT) {
if (resultCode == Activity.RESULT_OK) {

was credential: Credential = data !!. getParcelableExtra (Credential.EXTRA_KEY)
// credential.getId (); <- must handle phone number strictly
}
}

}

How to test the demo:

NOTE : From the server SMS format should follow: –
A) prefix: <#>
B) content: Your OTP code is: 45678
C ) postfix: program keyhash from your key store (Debug, Release)

For example :
<#> Your OTP code is: 45678

OutPut

Technology Used

Tools : Android Studio v3.3.1 with API 28 (Pie 9.0), SDK
Language: Kotlin, XML


Conclusion

With the new Play Store update, Google now allows Android app users to choose which ones to allow access to the SMS or call logs. The above-mentioned SMS Retriever API example is useful for various B2C service providers who have direct contact with their customers. Businesses from finance, e-commerce and the fashion industry can find this feature more useful for their mobile apps.

Using this Android tutorial, we've learned how to integrate the SMS Retriever API into the Android app. You can get the source of this Android app tutorial from Github.

As Google rejects these Android apps from submitting to the Play Store, which does not comply with current app policies. So, to avoid rejection of your own Android app in the Google Play store, you must include the automatic SMS verification feature using SMS Retriever API Android. If you want to integrate automatic SMS verification process into your Android development project, contact our experienced android app developer.

This page was last edited on February 22, 2019 at 8:54.

Do you have an appide?

Get your free consultation now




Source link