From 03803046496265203bd4da386b6b8290bb2830bd Mon Sep 17 00:00:00 2001 From: divya0319 Date: Sat, 23 Mar 2019 16:27:46 +0530 Subject: [PATCH] Permission Denied listener Added --- .../com/stfalcon/smsverifycatcher_sample/MainActivity.java | 4 ++-- .../smsverifycatcher/PermissionDeniedListener.java | 5 +++++ .../com/stfalcon/smsverifycatcher/SmsVerifyCatcher.java | 7 +++++-- 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 smsverifycatcher/src/main/java/com/stfalcon/smsverifycatcher/PermissionDeniedListener.java diff --git a/sample/src/main/java/com/stfalcon/smsverifycatcher_sample/MainActivity.java b/sample/src/main/java/com/stfalcon/smsverifycatcher_sample/MainActivity.java index 31291b7..866f89d 100644 --- a/sample/src/main/java/com/stfalcon/smsverifycatcher_sample/MainActivity.java +++ b/sample/src/main/java/com/stfalcon/smsverifycatcher_sample/MainActivity.java @@ -14,7 +14,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -public class MainActivity extends AppCompatActivity { +public class MainActivity extends AppCompatActivity implements PermissionDeniedListener { private SmsVerifyCatcher smsVerifyCatcher; @Override @@ -83,6 +83,6 @@ protected void onStop() { @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); - smsVerifyCatcher.onRequestPermissionsResult(requestCode, permissions, grantResults); + smsVerifyCatcher.onRequestPermissionsResult(requestCode, permissions, grantResults, this); } } diff --git a/smsverifycatcher/src/main/java/com/stfalcon/smsverifycatcher/PermissionDeniedListener.java b/smsverifycatcher/src/main/java/com/stfalcon/smsverifycatcher/PermissionDeniedListener.java new file mode 100644 index 0000000..231c137 --- /dev/null +++ b/smsverifycatcher/src/main/java/com/stfalcon/smsverifycatcher/PermissionDeniedListener.java @@ -0,0 +1,5 @@ +package com.stfalcon.smsverifycatcher; + +public interface PermissionDeniedListener { + void onPermissionDenied(); +} diff --git a/smsverifycatcher/src/main/java/com/stfalcon/smsverifycatcher/SmsVerifyCatcher.java b/smsverifycatcher/src/main/java/com/stfalcon/smsverifycatcher/SmsVerifyCatcher.java index 5bce508..ada43ce 100644 --- a/smsverifycatcher/src/main/java/com/stfalcon/smsverifycatcher/SmsVerifyCatcher.java +++ b/smsverifycatcher/src/main/java/com/stfalcon/smsverifycatcher/SmsVerifyCatcher.java @@ -110,14 +110,17 @@ public void setFilter(String regexp) { this.filter = regexp; } - public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { + public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults, PermissionDeniedListener permissionDeniedListener) { switch (requestCode) { case PERMISSION_REQUEST_CODE: if (grantResults.length > 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED) { registerReceiver(); - } + } else { + Toast.makeText(activity, "Permission denied, you have to manually enter OTP now", Toast.LENGTH_LONG).show(); + permissionDeniedListener.onPermissionDenied(); + } break; default: break;