Auto Detect OTP Android

Android Library To Auto Detect OTP Without Sms Permissions







Apache License Version 2.0



Download API

AutoDetectOTPAndroid is an Android libary to Integrate Auto Detect OTP With Out Sms Permissions Required To Your Android Appliaction Essaily With less Stuff.


1. Add the following to your build.gradle.

repositories {
    maven {
        url  "" 

dependencies {
  implementation 'in.androidhunt.otp:AutoDetectOTPAndroid:1.0.0'

2. Example Message Format and Generating Hash Code

       //Example Message Format

        <#>Your AndroidHunt OTP is: 8686. ynfd/rIwy/+

        ynfd/rIwy/+  is the hash code of your Application

       //There are Two  Ways To Genearate Hash Code One Is By Using Command Line
        keytool -exportcert -alias YOUR_KEYSTORE_ALIAS -keystore YOUR_KEYSTORE_FILE | xxd -p | tr -d "[:space:]" | echo -n com.example.myapp `cat` | sha256sum | tr -d "[:space:]-" | xxd -r -p | base64 | cut -c1-11

      //Other Way  By Doing Programatically Inside The Application.
      //Here You get Hash code by Using With Our Library
      String hashCode = AutoDetectOTP.getHashCode(this);
      // above string like this "ynfd/rIwy/+"

Obtain the user's phone number

3. Obtain the user's phone number Using hint picker with prompt

        AutoDetectOTP autoDetectOTP=new AutoDetectOTP(this);
        //To display List Of Phone No Linked with Google Account  By showing Dialog as Shown Above

        //we can get phone number onActivity Result when User Picked From prompt
           protected void onActivityResult(int requestCode, int resultCode, Intent data) {
               super.onActivityResult(requestCode, resultCode, data);
               if (requestCode == AutoDetectOTP.RC_HINT) {
                   if (resultCode == RESULT_OK) {
                   String phoneNo=autoDetectOTP.getPhoneNo(data);

                   else {
                   //nothing selected



4. Auto Detect OTP Usage

        AutoDetectOTP autoDetectOTP=new AutoDetectOTP(this);
        autoDetectOTP.startSmsRetriver(new AutoDetectOTP.SmsCallback() {
                  public void connectionfailed() {

                      //do something here on failure
                      Toast.makeText(OtpActivity.this,"Failed", Toast.LENGTH_SHORT).show();

                  public void connectionSuccess(Void aVoid) {
                      //do something here on success
                      Toast.makeText(OtpActivity.this,"Success", Toast.LENGTH_SHORT).show();

                  public void smsCallback(String sms) {
                  //  Get Sms Message Here pick what want from message here
                      if(sms.contains(":") && sms.contains(".")) {
                          String otp = sms.substring( sms.indexOf(":")+1 , sms.indexOf(".") ).trim();
                          Toast.makeText(OtpActivity.this,"The OTP is " + otp, Toast.LENGTH_SHORT).show();
              // Finally Stop Sms Retriver BY Calling  autoDetectOTP.stopSmsReciever() On OnDestroy As  Shown Below
                  protected void onDestroy() {

    Copyright 2019 Pratheep Chowdhary.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
Default image
pratheep kanati
I am a passionate programmer who is not afraid of a challenge. I push myself to achieve my goals and I love to strive towards perfection. The only thing I want to focus on is how I can make the best out of the situation, and how I can make it shine.
Articles: 30

Leave a Reply