Prerequisites

If you are already using OTPLESS SDK for authentication, then you don’t need to use AutoRead SDK because OTPLESS SDK auto reads the OTP itself. AutoRead SDK is to be used by merchants using OTPLESS APIs or some other vendor for authentication.

WhatsApp OTP AutoRead

  1. Get the OTP message template whitelisted by OTPLESS Support Team for OTPs that the users will receive on WhatsApp.
  2. Make sure the app hash that is whitelisted by OTPLESS matches your app hash at application runtime. If the app hash is different from the whitelisted app hash, WhatsApp OTP AutoRead won’t work. You can follow this guide to generate your app hash.

SMS OTP AutoRead

  1. Make sure that the SMS template contains your app hash. You can follow this guide to generate your app hash.

Dependency

Add the following dependency to your build.gradle file:

dependencies {
    implementation("io.github.otpless-tech:otpless-autoread-sdk:0.1.4")
}

How Auto Read Works

Auto Read uses a broadcast service to detect and capture OTPs. To enable this feature, you need to whitelist the OTP template with your App Hash and Package Name with WhatsApp/Meta or pass the app hash in SMS Template.

How to Whitelist the Template

1

Generate the App Hash

Use the OTPless utility function to get the App Hash.

import the following class

Kotlin
import com.otpless.autoread.main.AutoReadSDK

To get the application signature in base64 return String and take first 11 characters

Kotlin
val appSignature = AutoReadSDK.getAppSignature(context).take(11)
2

Send Details for Whitelisting

Send the following details to support@otpless.com from your registered email ID:

  • App Hash
  • Package Name
  • App ID

Usage

To enable OTP AutoRead, use the following methods based on the type of OTP you want to auto-read:

SMS OTP AutoRead

Register for auto-reading OTPs from SMS by calling the registerSmsOtpReceiver method:

AutoReadSDK.registerSmsOtpReceiver(context) { otpAutoReadResult ->
    if (otpAutoReadResult.otp != null) {
        Log.d(TAG, otpAutoReadResult.otp)
    } else {
        // Handle error
        val errorMessage = otpAutoReadResult.errorMessage
    }
    // Unregister register once SMS is received
    AutoReadSDK.unregisterSmsOtpReceiver()
}

WhatsApp ZeroTap OTP AutoRead

  • WhatsApp ZeroTap OTP AutoRead works for devices with Android API level 24 (Nougat) and above. Register for auto-reading OTPs from WhatsApp by calling the registerWhatsAppZeroTap method:
AutoReadSDK.registerWhatsAppZeroTap(context) { otpAutoReadResult ->
    if (otpAutoReadResult.otp != null) {
        Log.d(TAG, otpAutoReadResult.otp)
    } else {
        // Handle error
        val errorMessage = otpAutoReadResult.errorMessage
    }
}

WhatsApp OneTap OTP AutoRead

  • WhatsApp OneTap OTP AutoRead works for devices with Android API level 24 (Nougat) and above. Register for auto-reading OTPs from WhatsApp by calling the registerWhatsAppOneTap method:
AutoReadSDK.registerWhatsAppOneTap(context) { otpAutoReadResult ->
    if (otpAutoReadResult.otp != null) {
        Log.d(TAG, otpAutoReadResult.otp)
    } else {
        // Handle error
        val errorMessage = otpAutoReadResult.errorMessage
    }
}

Additionally, ensure your activity is set to singleTop launch mode and exported attribute is true:

android:launchMode="singleTop"
android:exported="true"

Override the onNewIntent function to receive intent from WhatsApp for OneTap OTP AutoRead.

 override fun onNewIntent(intent: Intent) {
    super.onNewIntent(intent)
    if (AutoReadSDK.onNewIntent(intent)) return
}

If you are using both SMS and WhatsApp OTP AutoRead methods, then unregister the SMS OTP receiver as well if OTP is fetched via WhatsApp.