├── .github └── workflows │ └── android.yml ├── .gitignore ├── .idea ├── codeStyles │ └── Project.xml ├── gradle.xml ├── misc.xml ├── runConfigurations.xml └── vcs.xml ├── AutoDetectOtp.apk ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── in │ │ └── androidhunt │ │ └── otpdemo │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── in │ │ │ └── androidhunt │ │ │ └── otpdemo │ │ │ ├── MainActivity.java │ │ │ └── OtpActivity.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── bg_buttons.xml │ │ ├── black_circle.xml │ │ ├── ic_check.xml │ │ ├── ic_launcher_background.xml │ │ ├── ic_left.xml │ │ └── ic_right.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── activity_otp.xml │ │ ├── content_main.xml │ │ └── content_otp.xml │ │ ├── menu │ │ └── menu_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── in │ └── androidhunt │ └── otpdemo │ └── ExampleUnitTest.java ├── autodetectotpandroid ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── in │ │ └── androidhunt │ │ └── otp │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── in │ │ │ └── androidhunt │ │ │ └── otp │ │ │ ├── AppSignatureHelper.java │ │ │ └── AutoDetectOTP.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── in │ └── androidhunt │ └── otp │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshots ├── Screenshot_1.png ├── Screenshot_2.png ├── Screenshot_3.png └── flow-overview.png └── settings.gradle /.github/workflows/android.yml: -------------------------------------------------------------------------------- 1 | name: Android Pull Request & Master CI 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - 'master' 7 | push: 8 | branches: 9 | - 'master' 10 | 11 | jobs: 12 | test: 13 | name: Run Unit Tests 14 | runs-on: ubuntu-18.04 15 | 16 | steps: 17 | - uses: actions/checkout@v1 18 | - name: set up JDK 1.8 19 | uses: actions/setup-java@v1 20 | with: 21 | java-version: 1.8 22 | - name: Unit tests 23 | run: bash ./gradlew test --stacktrace 24 | 25 | apk: 26 | name: Generate APK 27 | runs-on: ubuntu-18.04 28 | 29 | steps: 30 | - uses: actions/checkout@v1 31 | - name: set up JDK 1.8 32 | uses: actions/setup-java@v1 33 | with: 34 | java-version: 1.8 35 | - name: Build debug APK 36 | run: bash ./gradlew assembleDebug --stacktrace 37 | - name: Upload APK 38 | uses: actions/upload-artifact@v1 39 | with: 40 | name: app 41 | path: app/build/outputs/apk/debug/app-debug.apk 42 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /AutoDetectOtp.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pratheepchowdhary/AutoDetectOTPAndroid/6a7ebb7a073996ebe50408b73b2f94e4c9b2550b/AutoDetectOtp.apk -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | AutoDetectOTPAndroid 2 | =============== 3 | 4 | [ ![Download](https://api.bintray.com/packages/pratheepchowdhary/maven/AutoDetectOTPAndroid/images/download.svg) ](https://bintray.com/pratheepchowdhary/maven/AutoDetectOTPAndroid/_latestVersion) 5 | [![API](https://img.shields.io/badge/API-15%2B-brightgreen.svg?style=flat)](https://bintray.com/pratheepchowdhary/maven/AutoDetectOTPAndroid/_latestVersion) 6 | 7 | [AutoDetectOTPAndroid](https://www.androidhunt.in) is an Android libary to Integrate Auto Detect OTP With Out Sms Permissions Required To Your Android Appliaction Essaily With less Stuff. 8 | 9 | 10 | Usage 11 | ----- 12 | 13 | **1.** Add the following to your **build.gradle**. 14 | ```groovy 15 | repositories { 16 | maven { 17 | url "https://dl.bintray.com/pratheepchowdhary/maven" 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation 'in.androidhunt.otp:AutoDetectOTPAndroid:1.0.0' 23 | } 24 | ``` 25 | **2.** Example Message Format and Generating Hash Code 26 | ```java 27 | //Example Message Format 28 | 29 | <#>Your AndroidHunt OTP is: 8686. ynfd/rIwy/+ 30 | 31 | ynfd/rIwy/+ is the hash code of your Application 32 | 33 | ``` 34 | ```java 35 | //There are Two Ways To Genearate Hash Code One Is By Using Command Line 36 | 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 37 | 38 | ``` 39 | ```java 40 | //Other Way By Doing Programatically Inside The Application. 41 | //Here You get Hash code by Using With Our Library 42 | String hashCode = AutoDetectOTP.getHashCode(this); 43 | // above string like this "ynfd/rIwy/+" 44 | 45 | ``` 46 |
47 | Obtain the user's phone number 48 |
49 | 50 | **3.** Obtain the user's phone number Using hint picker with prompt 51 | ```java 52 | AutoDetectOTP autoDetectOTP=new AutoDetectOTP(this); 53 | //To display List Of Phone No Linked with Google Account By showing Dialog as Shown Above 54 | autoDetectOTP.requestPhoneNoHint(); 55 | 56 | //we can get phone number onActivity Result when User Picked From prompt 57 | @Override 58 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 59 | super.onActivityResult(requestCode, resultCode, data); 60 | if (requestCode == AutoDetectOTP.RC_HINT) { 61 | if (resultCode == RESULT_OK) { 62 | String phoneNo=autoDetectOTP.getPhoneNo(data); 63 | 64 | } 65 | else { 66 | //nothing selected 67 | } 68 | 69 | } 70 | } 71 | 72 | ``` 73 |
74 | 75 | 76 | Verification 77 |
78 | 79 | **4.** Auto Detect OTP Usage 80 | ```java 81 | AutoDetectOTP autoDetectOTP=new AutoDetectOTP(this); 82 | autoDetectOTP.startSmsRetriver(new AutoDetectOTP.SmsCallback() { 83 | @Override 84 | public void connectionfailed() { 85 | 86 | //do something here on failure 87 | Toast.makeText(OtpActivity.this,"Failed", Toast.LENGTH_SHORT).show(); 88 | } 89 | 90 | @Override 91 | public void connectionSuccess(Void aVoid) { 92 | //do something here on success 93 | Toast.makeText(OtpActivity.this,"Success", Toast.LENGTH_SHORT).show(); 94 | } 95 | 96 | @Override 97 | public void smsCallback(String sms) { 98 | // Get Sms Message Here pick what want from message here 99 | if(sms.contains(":") && sms.contains(".")) { 100 | String otp = sms.substring( sms.indexOf(":")+1 , sms.indexOf(".") ).trim(); 101 | //otpTextView.setOTP(otp); 102 | Toast.makeText(OtpActivity.this,"The OTP is " + otp, Toast.LENGTH_SHORT).show(); 103 | } 104 | } 105 | }); 106 | ----------------- 107 | // Finally Stop Sms Retriver BY Calling autoDetectOTP.stopSmsReciever() On OnDestroy As Shown Below 108 | @Override 109 | protected void onDestroy() { 110 | super.onDestroy(); 111 | autoDetectOTP.stopSmsReciever(); 112 | } 113 | 114 | ``` 115 | ``` 116 | Licences 117 | -------- 118 | Copyright 2019 Pratheep Chowdhary. 119 | 120 | Licensed under the Apache License, Version 2.0 (the "License"); 121 | you may not use this file except in compliance with the License. 122 | You may obtain a copy of the License at 123 | 124 | http://www.apache.org/licenses/LICENSE-2.0 125 | 126 | Unless required by applicable law or agreed to in writing, software 127 | distributed under the License is distributed on an "AS IS" BASIS, 128 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 129 | See the License for the specific language governing permissions and 130 | limitations under the License. 131 | ``` 132 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | signingConfigs { 5 | config { 6 | keyAlias 'otp' 7 | keyPassword '123456' 8 | storeFile file('/home/pradeep/AndroidKey/otp.jks') 9 | storePassword '123456' 10 | } 11 | } 12 | compileSdkVersion 28 13 | defaultConfig { 14 | applicationId "in.androidhunt.otpdemo" 15 | minSdkVersion 15 16 | targetSdkVersion 28 17 | versionCode 1 18 | versionName "1.0" 19 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 20 | vectorDrawables.useSupportLibrary = true 21 | signingConfig signingConfigs.config 22 | } 23 | buildTypes { 24 | release { 25 | minifyEnabled false 26 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 27 | signingConfig signingConfigs.config 28 | } 29 | debug { 30 | signingConfig signingConfigs.config 31 | } 32 | } 33 | productFlavors { 34 | } 35 | } 36 | 37 | dependencies { 38 | implementation fileTree(include: ['*.jar'], dir: 'libs') 39 | implementation 'com.android.support:appcompat-v7:28.0.0' 40 | implementation 'com.github.aabhasr1:OtpView:1.0.5' 41 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 42 | implementation 'com.android.support:design:28.0.0' 43 | testImplementation 'junit:junit:4.12' 44 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 45 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 46 | implementation 'com.github.joielechong:countrycodepicker:2.2.0' 47 | implementation project(':autodetectotpandroid') 48 | } 49 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/in/androidhunt/otpdemo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package in.androidhunt.otpdemo; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("in.androidhunt.otpdemo", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 16 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/java/in/androidhunt/otpdemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package in.androidhunt.otpdemo; 2 | 3 | import android.content.ClipData; 4 | import android.content.ClipboardManager; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.os.Bundle; 8 | import android.support.design.widget.FloatingActionButton; 9 | import android.support.design.widget.Snackbar; 10 | import android.support.v7.app.AppCompatActivity; 11 | import android.support.v7.widget.AppCompatEditText; 12 | import android.support.v7.widget.Toolbar; 13 | import android.view.View; 14 | import android.view.Menu; 15 | import android.view.MenuItem; 16 | import android.widget.Button; 17 | import android.widget.TextView; 18 | import android.widget.Toast; 19 | 20 | import com.rilixtech.CountryCodePicker; 21 | 22 | import in.androidhunt.otp.AutoDetectOTP; 23 | 24 | public class MainActivity extends AppCompatActivity { 25 | AutoDetectOTP autoDetectOTP; 26 | CountryCodePicker countryCodePicker; 27 | AppCompatEditText edtPhoneNumber; 28 | String testMessage="<#>Your AndroidHunt OTP is: 8686. "; 29 | TextView test_message; 30 | Button copyMessage; 31 | @Override 32 | protected void onCreate(Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | setContentView(R.layout.activity_main); 35 | Toolbar toolbar = findViewById(R.id.toolbar); 36 | setSupportActionBar(toolbar); 37 | FloatingActionButton fab = findViewById(R.id.fab); 38 | countryCodePicker = findViewById(R.id.ccp); 39 | edtPhoneNumber = findViewById(R.id.phone_number_edt); 40 | countryCodePicker.registerPhoneNumberTextView(edtPhoneNumber); 41 | autoDetectOTP= new AutoDetectOTP(this); 42 | test_message=findViewById(R.id.message); 43 | copyMessage=findViewById(R.id.copy_message); 44 | 45 | fab.setOnClickListener(new View.OnClickListener() { 46 | @Override 47 | public void onClick(View view) { 48 | Intent intent=new Intent(MainActivity.this,OtpActivity.class); 49 | intent.putExtra("NO",countryCodePicker.getFullNumberWithPlus()); 50 | startActivity(intent); 51 | } 52 | }); 53 | autoDetectOTP.requestPhoneNoHint(); 54 | String message=testMessage+AutoDetectOTP.getHashCode(this); 55 | test_message.setText("Hash Code For This App is "+AutoDetectOTP.getHashCode(this)+"\n"+message); 56 | copyMessage.setOnClickListener(new View.OnClickListener() { 57 | @Override 58 | public void onClick(View v) { 59 | ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); 60 | ClipData clip = ClipData.newPlainText("label", testMessage+AutoDetectOTP.getHashCode(MainActivity.this)); 61 | if (clipboard == null) return; 62 | clipboard.setPrimaryClip(clip); 63 | Toast.makeText(MainActivity.this,"Message Copied To ClipBoard", Toast.LENGTH_SHORT).show(); 64 | } 65 | }); 66 | 67 | 68 | } 69 | 70 | @Override 71 | public boolean onCreateOptionsMenu(Menu menu) { 72 | // Inflate the menu; this adds items to the action bar if it is present. 73 | getMenuInflater().inflate(R.menu.menu_main, menu); 74 | return true; 75 | } 76 | 77 | @Override 78 | public boolean onOptionsItemSelected(MenuItem item) { 79 | // Handle action bar item clicks here. The action bar will 80 | // automatically handle clicks on the Home/Up button, so long 81 | // as you specify a parent activity in AndroidManifest.xml. 82 | int id = item.getItemId(); 83 | 84 | //noinspection SimplifiableIfStatement 85 | if (id == R.id.action_settings) { 86 | return true; 87 | } 88 | 89 | return super.onOptionsItemSelected(item); 90 | } 91 | @Override 92 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 93 | super.onActivityResult(requestCode, resultCode, data); 94 | if (requestCode == AutoDetectOTP.RC_HINT) { 95 | if (resultCode == RESULT_OK) { 96 | countryCodePicker.setFullNumber(autoDetectOTP.getPhoneNo(data)); 97 | 98 | Snackbar.make(findViewById(R.id.root_view), autoDetectOTP.getPhoneNo(data), Snackbar.LENGTH_LONG) 99 | .setAction("Action", null).show(); 100 | } else { 101 | } 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /app/src/main/java/in/androidhunt/otpdemo/OtpActivity.java: -------------------------------------------------------------------------------- 1 | package in.androidhunt.otpdemo; 2 | 3 | import android.content.ClipData; 4 | import android.content.ClipboardManager; 5 | import android.content.Context; 6 | import android.os.Build; 7 | import android.os.Bundle; 8 | import android.os.CountDownTimer; 9 | import android.os.Handler; 10 | import android.support.design.widget.AppBarLayout; 11 | import android.support.v7.app.AppCompatActivity; 12 | import android.support.v7.widget.Toolbar; 13 | import android.view.View; 14 | import android.view.Window; 15 | import android.widget.TextView; 16 | import android.widget.Toast; 17 | import java.util.concurrent.TimeUnit; 18 | import in.aabhasjindal.otptextview.OTPListener; 19 | import in.aabhasjindal.otptextview.OtpTextView; 20 | import in.androidhunt.otp.AutoDetectOTP; 21 | 22 | public class OtpActivity extends AppCompatActivity { 23 | private String otpnN0; 24 | TextView timer; 25 | AutoDetectOTP autoDetectOTP; 26 | private OtpTextView otpTextView; 27 | CountDownTimer countDownTimer= new CountDownTimer(180000, 1000) { 28 | @Override 29 | public void onTick(long millisUntilFinished) { 30 | timer.setText(millisecondsToTime(millisUntilFinished)); 31 | } 32 | @Override 33 | public void onFinish() { 34 | timer.setText(""); 35 | } 36 | }; 37 | Handler handler=new Handler(); 38 | Runnable runnable=new Runnable() { 39 | @Override 40 | public void run() { 41 | if(otpnN0!=null&&otpnN0.equals("1234")){ 42 | otpTextView.showSuccess(); 43 | countDownTimer.cancel(); 44 | } 45 | else { 46 | otpTextView.showError(); 47 | } 48 | } 49 | }; 50 | @Override 51 | protected void onCreate(Bundle savedInstanceState) { 52 | supportRequestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY); 53 | super.onCreate(savedInstanceState); 54 | setContentView(R.layout.activity_otp); 55 | autoDetectOTP=new AutoDetectOTP(this); 56 | Toolbar toolbar = findViewById(R.id.toolbar); 57 | TextView phoneview=findViewById(R.id.phone_); 58 | timer= findViewById(R.id.timer); 59 | setSupportActionBar(toolbar); 60 | getSupportActionBar().setBackgroundDrawable(null); 61 | AppBarLayout app= findViewById(R.id.appbar); 62 | if(Build.VERSION.SDK_INT >=Build.VERSION_CODES.LOLLIPOP) { 63 | app.setOutlineProvider(null); 64 | } 65 | findViewById(R.id.fab_previos).setOnClickListener(new View.OnClickListener() { 66 | @Override 67 | public void onClick(View v) { 68 | onBackPressed(); 69 | } 70 | }); 71 | String no=getIntent().getStringExtra("NO"); 72 | if(no!=null){ 73 | phoneview.append(no); 74 | } 75 | otpTextView = findViewById(R.id.otp_view); 76 | otpTextView.requestFocusOTP(); 77 | otpTextView.setOtpListener(new OTPListener() {; 78 | 79 | @Override 80 | public void onInteractionListener() { 81 | 82 | } 83 | 84 | @Override 85 | public void onOTPComplete(String otp) { 86 | otpnN0=otp; 87 | Toast.makeText(OtpActivity.this,"The OTP is " + otp, Toast.LENGTH_SHORT).show(); 88 | handler.postDelayed(runnable,100); 89 | 90 | } 91 | }); 92 | countDownTimer.start(); 93 | autoDetectOTP.startSmsRetriver(new AutoDetectOTP.SmsCallback() { 94 | @Override 95 | public void connectionfailed() { 96 | Toast.makeText(OtpActivity.this,"Failed", Toast.LENGTH_SHORT).show(); 97 | } 98 | 99 | @Override 100 | public void connectionSuccess(Void aVoid) { 101 | Toast.makeText(OtpActivity.this,"Success", Toast.LENGTH_SHORT).show(); 102 | } 103 | 104 | @Override 105 | public void smsCallback(String sms) { 106 | if(sms.contains(":") && sms.contains(".")) { 107 | String otp = sms.substring( sms.indexOf(":")+1 , sms.indexOf(".") ).trim(); 108 | otpTextView.setOTP(otp); 109 | Toast.makeText(OtpActivity.this,"The OTP is " + otp, Toast.LENGTH_SHORT).show(); 110 | } 111 | } 112 | }); 113 | findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() { 114 | @Override 115 | public void onClick(View v) { 116 | ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); 117 | ClipData clip = ClipData.newPlainText("label", AutoDetectOTP.getHashCode(OtpActivity.this)); 118 | if (clipboard == null) return; 119 | clipboard.setPrimaryClip(clip); 120 | Toast.makeText(OtpActivity.this,AutoDetectOTP.getHashCode(OtpActivity.this), Toast.LENGTH_SHORT).show(); 121 | } 122 | }); 123 | } 124 | @Override 125 | protected void onDestroy() { 126 | 127 | if (countDownTimer != null) { 128 | countDownTimer.onFinish(); 129 | countDownTimer.cancel(); 130 | } 131 | super.onDestroy(); 132 | } 133 | @Override 134 | protected void onStop() { 135 | super.onStop(); 136 | autoDetectOTP.stopSmsReciever(); 137 | if (countDownTimer != null) { 138 | countDownTimer.onFinish(); 139 | countDownTimer.cancel(); 140 | } 141 | } 142 | private String millisecondsToTime(long milliseconds) { 143 | 144 | return "Time remaining " + String.format("%d : %d ", 145 | TimeUnit.MILLISECONDS.toMinutes(milliseconds), 146 | TimeUnit.MILLISECONDS.toSeconds(milliseconds) - 147 | TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(milliseconds))); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/bg_buttons.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/black_circle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_check.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_left.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_right.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | 21 | 22 | 23 | 24 | 25 | 26 | 35 | 36 |