Skip to content

Commit

Permalink
feat: ContextCompat.checkSelfPermission run with try-catch
Browse files Browse the repository at this point in the history
  • Loading branch information
wn-na committed May 22, 2024
1 parent f32ff36 commit 5b983a6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,22 @@ private boolean requestStoragePermission() {
return true;
}

String requestPermission = Build.VERSION.SDK_INT >= 33 // Build.VERSION_CODES.TIRAMISU
? "android.permission.READ_MEDIA_IMAGES" // Manifest.permission.READ_MEDIA_IMAGES
: Manifest.permission.READ_EXTERNAL_STORAGE;

if (ContextCompat.checkSelfPermission(getCurrentActivity(),
requestPermission) == PackageManager.PERMISSION_GRANTED) {
Log.d(NAME, "Permission is granted");
return true;
} else {
Log.d(NAME, "Permission is revoked");
ActivityCompat.requestPermissions(getCurrentActivity(), new String[] { requestPermission }, 1);
try {
String requestPermission = Build.VERSION.SDK_INT >= 33 // Build.VERSION_CODES.TIRAMISU
? "android.permission.READ_MEDIA_IMAGES" // Manifest.permission.READ_MEDIA_IMAGES
: Manifest.permission.READ_EXTERNAL_STORAGE;

if (ContextCompat.checkSelfPermission(getCurrentActivity(),
requestPermission) == PackageManager.PERMISSION_GRANTED) {
Log.d(NAME, "Permission is granted");
return true;
} else {
Log.d(NAME, "Permission is revoked");
ActivityCompat.requestPermissions(getCurrentActivity(), new String[] { requestPermission }, 1);
return false;
}
} catch (Exception e) {
Log.e(NAME, "requestStoragePermission has raise Exception: " + e.getLocalizedMessage());
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-capture-protection",
"version": "1.9.6",
"version": "1.9.7",
"description": "It’s a library for React Native to control simple capture events(i.e. Screenshot or Screen record)",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down

0 comments on commit 5b983a6

Please sign in to comment.