Skip to content

Commit

Permalink
Add sdk33 checks
Browse files Browse the repository at this point in the history
  • Loading branch information
VishalNehra committed Oct 30, 2023
1 parent 58b4ff0 commit 9f152fc
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.google.android.material.snackbar.Snackbar;

import android.Manifest;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
Expand Down Expand Up @@ -91,9 +92,13 @@ public void onRequestPermissionsResult(
public boolean checkStoragePermission() {
// Verify that all required contact permissions have been granted.
if (SDK_INT >= Build.VERSION_CODES.R) {
return ActivityCompat.checkSelfPermission(
this, Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
== PackageManager.PERMISSION_GRANTED;
return (ActivityCompat.checkSelfPermission(
this, Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
== PackageManager.PERMISSION_GRANTED)
|| (ActivityCompat.checkSelfPermission(
this, Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)
== PackageManager.PERMISSION_GRANTED)
|| Environment.isExternalStorageManager();
} else {
return ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED;
Expand Down Expand Up @@ -266,6 +271,16 @@ private void requestAllFilesAccessPermission(
new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
.setData(Uri.parse("package:" + getPackageName()));
startActivity(intent);
} catch (ActivityNotFoundException anf) {
// fallback
try {
Intent intent =
new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)
.setData(Uri.parse("package:$packageName"));
startActivity(intent);
} catch (Exception e) {
AppConfig.toast(this, getString(R.string.grantfailed));
}
} catch (Exception e) {
Log.e(TAG, "Failed to initial activity to grant all files access", e);
AppConfig.toast(this, getString(R.string.grantfailed));
Expand Down

0 comments on commit 9f152fc

Please sign in to comment.