├── .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 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
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 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
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 | [  ](https://bintray.com/pratheepchowdhary/maven/AutoDetectOTPAndroid/_latestVersion)
5 | [](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 |

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 |
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 |
45 |
46 |
53 |
54 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_otp.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
21 |
22 |
23 |
24 |
25 |
26 |
33 |
34 |
41 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
21 |
22 |
26 |
27 |
32 |
33 |
38 |
39 |
45 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_otp.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
22 |
23 |
36 |
37 |
63 |
64 |
76 |
77 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pratheepchowdhary/AutoDetectOTPAndroid/6a7ebb7a073996ebe50408b73b2f94e4c9b2550b/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pratheepchowdhary/AutoDetectOTPAndroid/6a7ebb7a073996ebe50408b73b2f94e4c9b2550b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pratheepchowdhary/AutoDetectOTPAndroid/6a7ebb7a073996ebe50408b73b2f94e4c9b2550b/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pratheepchowdhary/AutoDetectOTPAndroid/6a7ebb7a073996ebe50408b73b2f94e4c9b2550b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pratheepchowdhary/AutoDetectOTPAndroid/6a7ebb7a073996ebe50408b73b2f94e4c9b2550b/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pratheepchowdhary/AutoDetectOTPAndroid/6a7ebb7a073996ebe50408b73b2f94e4c9b2550b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pratheepchowdhary/AutoDetectOTPAndroid/6a7ebb7a073996ebe50408b73b2f94e4c9b2550b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pratheepchowdhary/AutoDetectOTPAndroid/6a7ebb7a073996ebe50408b73b2f94e4c9b2550b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pratheepchowdhary/AutoDetectOTPAndroid/6a7ebb7a073996ebe50408b73b2f94e4c9b2550b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pratheepchowdhary/AutoDetectOTPAndroid/6a7ebb7a073996ebe50408b73b2f94e4c9b2550b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #4C0DD1
4 | #081FB3
5 | #D81B60
6 | #8509f2
7 | #e60000
8 | #33cc33
9 | #292828
10 | #ffffff
11 | #606060
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 16dp
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AutoDetectOTPAndroid
3 | Settings
4 | OtpActivity
5 | Please type the verification code sent to\n
6 | Verification Code
7 | SHOW ERROR
8 | SHOW Success
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/test/java/in/androidhunt/otpdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package in.androidhunt.otpdemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/autodetectotpandroid/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/autodetectotpandroid/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | ext {
3 | // repo name
4 | bintrayRepo = 'maven'
5 | //project name
6 | bintrayName = 'AutoDetectOTPAndroid'
7 | //enter your package name
8 | publishedGroupId = 'in.androidhunt.otp'
9 | //project name
10 | libraryName = 'AutoDetectOTPAndroid'
11 | //project name
12 | artifact = 'AutoDetectOTPAndroid'
13 | // some description about your library
14 | libraryDescription = 'AutoDetectOTPAndroid is an Android libary to Integrate Auto Detect OTP With Out Sms Permissions Required To Your Android Appliaction Essaily With less Stuff'
15 | // github
16 | siteUrl = 'https://github.com/pratheepchowdhary/AutoDetectOTPAndroid'
17 | gitUrl = 'https://github.com/pratheepchowdhary/AutoDetectOTPAndroid.git'
18 |
19 | libraryVersion = '1.0.0'
20 |
21 | developerId = 'pratheepchowdhary'
22 | developerName = 'Pratheep Kanati'
23 | developerEmail = 'pratheepkanati@gmail.com'
24 |
25 | licenseName = 'The Apache Software License, Version 2.0'
26 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
27 | allLicenses = ["Apache-2.0"]
28 | }
29 |
30 | android {
31 | compileSdkVersion 28
32 |
33 |
34 |
35 | defaultConfig {
36 | minSdkVersion 15
37 | targetSdkVersion 28
38 | versionCode 1
39 | versionName "1.0.0"
40 |
41 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
42 |
43 | }
44 |
45 | buildTypes {
46 | release {
47 | minifyEnabled false
48 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
49 | }
50 | }
51 |
52 | }
53 |
54 | dependencies {
55 | implementation fileTree(include: ['*.jar'], dir: 'libs')
56 | implementation 'com.google.android.gms:play-services-auth-api-phone:16.0.0'
57 | implementation 'com.google.android.gms:play-services-base:16.1.0'
58 | implementation 'com.google.android.gms:play-services-identity:16.0.0'
59 | implementation 'com.google.android.gms:play-services-auth:16.0.1'
60 | implementation 'com.android.support:appcompat-v7:28.0.0'
61 | testImplementation 'junit:junit:4.12'
62 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
63 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
64 |
65 |
66 | }
67 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
68 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
--------------------------------------------------------------------------------
/autodetectotpandroid/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 |
--------------------------------------------------------------------------------
/autodetectotpandroid/src/androidTest/java/in/androidhunt/otp/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package in.androidhunt.otp;
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.otp.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/autodetectotpandroid/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/autodetectotpandroid/src/main/java/in/androidhunt/otp/AppSignatureHelper.java:
--------------------------------------------------------------------------------
1 | package in.androidhunt.otp;
2 |
3 | import android.content.Context;
4 | import android.content.ContextWrapper;
5 | import android.content.pm.PackageManager;
6 | import android.content.pm.Signature;
7 | import android.os.Build;
8 | import android.util.Base64;
9 | import android.util.Log;
10 |
11 | import java.nio.charset.Charset;
12 | import java.nio.charset.StandardCharsets;
13 | import java.security.MessageDigest;
14 | import java.security.NoSuchAlgorithmException;
15 | import java.util.ArrayList;
16 | import java.util.Arrays;
17 |
18 | public class AppSignatureHelper extends ContextWrapper {
19 | public static final String TAG = AppSignatureHelper.class.getSimpleName();
20 |
21 | private static final String HASH_TYPE = "SHA-256";
22 | public static final int NUM_HASHED_BYTES = 9;
23 | public static final int NUM_BASE64_CHAR = 11;
24 |
25 | public AppSignatureHelper(Context context) {
26 | super(context);
27 | }
28 |
29 | /**
30 | * Get all the app signatures for the current package
31 | */
32 | public ArrayList getAppSignatures() {
33 | ArrayList appCodes = new ArrayList<>();
34 |
35 | try {
36 | // Get all package signatures for the current package
37 | String packageName = getPackageName();
38 | PackageManager packageManager = getPackageManager();
39 | Signature[] signatures = packageManager.getPackageInfo(packageName,
40 | PackageManager.GET_SIGNATURES).signatures;
41 |
42 | // For each signature create a compatible hash
43 | for (Signature signature : signatures) {
44 | String hash = hash(packageName, signature.toCharsString());
45 | if (hash != null) {
46 | appCodes.add(String.format("%s", hash));
47 | }
48 | }
49 | } catch (PackageManager.NameNotFoundException e) {
50 | Log.e(TAG, "Unable to find package to obtain hash.", e);
51 | }
52 | return appCodes;
53 | }
54 |
55 | private static String hash(String packageName, String signature) {
56 | String appInfo = packageName + " " + signature;
57 | try {
58 | MessageDigest messageDigest = MessageDigest.getInstance(HASH_TYPE);
59 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
60 | messageDigest.update(appInfo.getBytes(StandardCharsets.UTF_8));
61 | }
62 | else {
63 | messageDigest.update(appInfo.getBytes(Charset.forName("UTF-8")));
64 | }
65 | byte[] hashSignature = messageDigest.digest();
66 |
67 | // truncated into NUM_HASHED_BYTES
68 | hashSignature = Arrays.copyOfRange(hashSignature, 0, NUM_HASHED_BYTES);
69 | // encode into Base64
70 | String base64Hash = Base64.encodeToString(hashSignature, Base64.NO_PADDING | Base64.NO_WRAP);
71 | base64Hash = base64Hash.substring(0, NUM_BASE64_CHAR);
72 |
73 | Log.e(TAG, String.format("pkg: %s -- hash: %s", packageName, base64Hash));
74 | return base64Hash;
75 | } catch (NoSuchAlgorithmException e) {
76 | Log.e(TAG, "hash:NoSuchAlgorithm", e);
77 | }
78 | return null;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/autodetectotpandroid/src/main/java/in/androidhunt/otp/AutoDetectOTP.java:
--------------------------------------------------------------------------------
1 | package in.androidhunt.otp;
2 |
3 | import android.app.PendingIntent;
4 | import android.content.BroadcastReceiver;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.content.IntentFilter;
8 | import android.content.IntentSender;
9 | import android.os.Bundle;
10 | import android.support.annotation.NonNull;
11 | import android.support.annotation.Nullable;
12 | import android.support.v7.app.AppCompatActivity;
13 | import android.util.Log;
14 | import com.google.android.gms.auth.api.Auth;
15 | import com.google.android.gms.auth.api.credentials.Credential;
16 | import com.google.android.gms.auth.api.credentials.CredentialPickerConfig;
17 | import com.google.android.gms.auth.api.credentials.HintRequest;
18 | import com.google.android.gms.auth.api.phone.SmsRetriever;
19 | import com.google.android.gms.auth.api.phone.SmsRetrieverClient;
20 | import com.google.android.gms.common.ConnectionResult;
21 | import com.google.android.gms.common.api.CommonStatusCodes;
22 | import com.google.android.gms.common.api.GoogleApiClient;
23 | import com.google.android.gms.common.api.Status;
24 | import com.google.android.gms.tasks.OnFailureListener;
25 | import com.google.android.gms.tasks.OnSuccessListener;
26 | import com.google.android.gms.tasks.Task;
27 |
28 | /**
29 | * Created by Pratheep Chowdhary on 02,March,2019
30 | */
31 | public class AutoDetectOTP {
32 | public static final int RC_HINT = 1000;
33 | private SmsCallback smsCallback;
34 | private GoogleApiClient googleApiClient;
35 | private Context context;
36 | private BroadcastReceiver chargerReceiver;
37 | private AppCompatActivity appCompatActivity;
38 | private IntentFilter intentFilter;
39 | public AutoDetectOTP(Context context) {
40 | this.appCompatActivity = (AppCompatActivity) context;
41 | this.context = appCompatActivity.getApplicationContext();
42 | }
43 |
44 | public void requestPhoneNoHint() {
45 | googleApiClient = new GoogleApiClient.Builder(context)
46 | .enableAutoManage(appCompatActivity, new GoogleApiClient.OnConnectionFailedListener() {
47 | @Override
48 | public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
49 | }
50 | })
51 | .addApi(Auth.CREDENTIALS_API)
52 | .build();
53 | HintRequest hintRequest = new HintRequest.Builder()
54 | .setHintPickerConfig(new CredentialPickerConfig.Builder()
55 | .setShowCancelButton(true)
56 | .build())
57 | .setPhoneNumberIdentifierSupported(true)
58 | .build();
59 |
60 | PendingIntent intent =
61 | Auth.CredentialsApi.getHintPickerIntent(googleApiClient, hintRequest);
62 | try {
63 | appCompatActivity.startIntentSenderForResult(intent.getIntentSender(), RC_HINT, null, 0, 0, 0);
64 | } catch (IntentSender.SendIntentException e) {
65 | Log.e("PHONE_HINT", "Could not start hint picker Intent", e);
66 | }
67 | }
68 |
69 | public void requestPhoneNoHint(final Callback callback) {
70 | googleApiClient = new GoogleApiClient.Builder(context)
71 | .enableAutoManage(appCompatActivity, new GoogleApiClient.OnConnectionFailedListener() {
72 | @Override
73 | public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
74 | }
75 | })
76 | .addApi(Auth.CREDENTIALS_API)
77 | .build();
78 | googleApiClient = new GoogleApiClient.Builder(context)
79 | .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
80 | @Override
81 | public void onConnected(@Nullable Bundle bundle) {
82 | callback.connectionSuccess(bundle);
83 | }
84 |
85 | @Override
86 | public void onConnectionSuspended(int i) {
87 | callback.connectionSuspend(i);
88 | }
89 | })
90 | .enableAutoManage(appCompatActivity, new GoogleApiClient.OnConnectionFailedListener() {
91 | @Override
92 | public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
93 | callback.connectionfailed(connectionResult);
94 | }
95 | })
96 | .addApi(Auth.CREDENTIALS_API)
97 | .build();
98 | HintRequest hintRequest = new HintRequest.Builder()
99 | .setHintPickerConfig(new CredentialPickerConfig.Builder()
100 | .setShowCancelButton(true)
101 | .build())
102 | .setPhoneNumberIdentifierSupported(true)
103 | .build();
104 |
105 |
106 | PendingIntent intent =
107 | Auth.CredentialsApi.getHintPickerIntent(googleApiClient, hintRequest);
108 | try {
109 | appCompatActivity.startIntentSenderForResult(intent.getIntentSender(), RC_HINT, null, 0, 0, 0);
110 | } catch (IntentSender.SendIntentException e) {
111 | Log.e("PHONE_HINT", "Could not start hint picker Intent", e);
112 | }
113 | }
114 |
115 | public void startSmsRetriver(final SmsCallback smsCallback) {
116 | registerReceiver();
117 | this.smsCallback = smsCallback;
118 | // Get an instance of SmsRetrieverClient, used to start listening for a matching
119 | // SMS message.
120 | SmsRetrieverClient client = SmsRetriever.getClient(context);
121 |
122 | // Starts SmsRetriever, which waits for ONE matching SMS message until timeout
123 | // (5 minutes). The matching SMS message will be sent via a Broadcast Intent with
124 | // action SmsRetriever#SMS_RETRIEVED_ACTION.
125 | Task task = client.startSmsRetriever();
126 | // Listen for success/failure of the start Task. If in a background thread, this
127 | // can be made blocking using Tasks.await(task, [timeout]);
128 | task.addOnSuccessListener(new OnSuccessListener() {
129 | @Override
130 | public void onSuccess(Void aVoid) {
131 | Log.e("SMSRE","success");
132 | smsCallback.connectionSuccess(aVoid);
133 | }
134 | });
135 |
136 | task.addOnFailureListener(new OnFailureListener() {
137 | @Override
138 | public void onFailure(@NonNull Exception e) {
139 | smsCallback.connectionfailed();
140 | }
141 | });
142 |
143 | }
144 |
145 | public String getPhoneNo(Intent data) {
146 | Credential cred = data.getParcelableExtra(Credential.EXTRA_KEY);
147 | return cred.getId();
148 |
149 | }
150 |
151 | private void registerReceiver() {
152 | // filter to receive SMS
153 | intentFilter = new IntentFilter();
154 | intentFilter.addAction(SmsRetriever.SMS_RETRIEVED_ACTION);
155 |
156 | // receiver to receive and to get otp from SMS
157 | chargerReceiver = new BroadcastReceiver() {
158 | @Override
159 | public void onReceive(Context context, Intent intent) {
160 | if (SmsRetriever.SMS_RETRIEVED_ACTION.equals(intent.getAction())) {
161 | Bundle extras = intent.getExtras();
162 | Status status = (Status) extras.get(SmsRetriever.EXTRA_STATUS);
163 | switch (status.getStatusCode()) {
164 | case CommonStatusCodes.SUCCESS:
165 | // Get SMS message contents
166 | String message = (String) extras.get(SmsRetriever.EXTRA_SMS_MESSAGE);
167 | // Extract one-time code from the message and complete verification
168 | // by sending the code back to your server for SMS authenticity.
169 | smsCallback.smsCallback(message);
170 | stopSmsReciever();
171 | break;
172 | case CommonStatusCodes.TIMEOUT:
173 | // Waiting for SMS timed out (5 minutes)
174 | smsCallback.connectionfailed();
175 | break;
176 |
177 | }
178 | }
179 | }
180 | };
181 | appCompatActivity.getApplication().registerReceiver(chargerReceiver, intentFilter);
182 | }
183 |
184 | public void stopSmsReciever() {
185 | try {
186 | appCompatActivity.getApplicationContext().unregisterReceiver(chargerReceiver);
187 | }
188 | catch (IllegalArgumentException e){
189 | e.printStackTrace();
190 | }
191 | }
192 |
193 | ;
194 |
195 | public interface Callback {
196 | void connectionfailed(ConnectionResult connectionResult);
197 | void connectionSuspend(int i);
198 | void connectionSuccess(Bundle bundle);
199 | }
200 |
201 | public interface SmsCallback {
202 | void connectionfailed();
203 | void connectionSuccess(Void aVoid);
204 | void smsCallback(String sms);
205 | }
206 | public static String getHashCode(Context context){
207 | AppSignatureHelper appSignature = new AppSignatureHelper(context);
208 | Log.e(" getAppSignatures ",""+appSignature.getAppSignatures());
209 | return appSignature.getAppSignatures().get(0);
210 |
211 | }
212 |
213 |
214 | }
215 |
--------------------------------------------------------------------------------
/autodetectotpandroid/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AutoDetectOTPAndroid
3 |
4 |
--------------------------------------------------------------------------------
/autodetectotpandroid/src/test/java/in/androidhunt/otp/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package in.androidhunt.otp;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | google()
6 | jcenter()
7 |
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.3.0'
11 | classpath 'com.google.gms:google-services:4.2.0'
12 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
13 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
14 |
15 | // NOTE: Do not place your application dependencies here; they belong
16 | // in the individual module build.gradle files
17 | }
18 | }
19 |
20 | allprojects {
21 | repositories {
22 | google()
23 | jcenter()
24 | maven { url "https://jitpack.io" }
25 |
26 |
27 | }
28 | }
29 |
30 | task clean(type: Delete) {
31 | delete rootProject.buildDir
32 | }
33 | subprojects {
34 | project.configurations.all {
35 | resolutionStrategy.eachDependency { details ->
36 | if (details.requested.group == 'com.android.support'
37 | && !details.requested.name.contains('multidex') ) {
38 | details.useVersion "28.0.0"
39 | }
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
15 |
16 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pratheepchowdhary/AutoDetectOTPAndroid/6a7ebb7a073996ebe50408b73b2f94e4c9b2550b/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Mar 02 10:22:44 IST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/screenshots/Screenshot_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pratheepchowdhary/AutoDetectOTPAndroid/6a7ebb7a073996ebe50408b73b2f94e4c9b2550b/screenshots/Screenshot_1.png
--------------------------------------------------------------------------------
/screenshots/Screenshot_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pratheepchowdhary/AutoDetectOTPAndroid/6a7ebb7a073996ebe50408b73b2f94e4c9b2550b/screenshots/Screenshot_2.png
--------------------------------------------------------------------------------
/screenshots/Screenshot_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pratheepchowdhary/AutoDetectOTPAndroid/6a7ebb7a073996ebe50408b73b2f94e4c9b2550b/screenshots/Screenshot_3.png
--------------------------------------------------------------------------------
/screenshots/flow-overview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pratheepchowdhary/AutoDetectOTPAndroid/6a7ebb7a073996ebe50408b73b2f94e4c9b2550b/screenshots/flow-overview.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':autodetectotpandroid'
2 |
--------------------------------------------------------------------------------