Skip to content

Commit ed88c49

Browse files
committed
feat: fix required permissions for android < 33
1 parent 27c5c67 commit ed88c49

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ android {
66
applicationId "com.codedead.deadhash"
77
minSdk 28
88
targetSdk 34
9-
versionName '1.8.1'
9+
versionName '1.8.2'
1010
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
11-
versionCode 11
11+
versionCode 12
1212
}
1313
buildTypes {
1414
release {

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools">
44

5+
<uses-permission
6+
android:name="android.permission.READ_EXTERNAL_STORAGE"
7+
android:maxSdkVersion="32" />
58
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
69
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
710
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />

app/src/main/java/com/codedead/deadhash/gui/MainActivity.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -538,29 +538,36 @@ public boolean onNavigationItemSelected(@NonNull final MenuItem item) {
538538
}
539539

540540
private void onClickSelectFile(final View v) {
541-
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_MEDIA_AUDIO) != PackageManager.PERMISSION_GRANTED
542-
|| ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_MEDIA_IMAGES) != PackageManager.PERMISSION_GRANTED
543-
|| ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_MEDIA_VIDEO) != PackageManager.PERMISSION_GRANTED) {
544-
Toast.makeText(getApplicationContext(), R.string.toast_no_permissions, Toast.LENGTH_LONG).show();
541+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
542+
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
543+
Toast.makeText(getApplicationContext(), R.string.toast_no_permissions, Toast.LENGTH_LONG).show();
544+
ActivityCompat.requestPermissions(MainActivity.this, new String[]{
545+
Manifest.permission.READ_EXTERNAL_STORAGE
546+
}, 0);
547+
548+
return;
549+
}
550+
} else {
551+
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_MEDIA_AUDIO) != PackageManager.PERMISSION_GRANTED
552+
|| ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_MEDIA_IMAGES) != PackageManager.PERMISSION_GRANTED
553+
|| ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_MEDIA_VIDEO) != PackageManager.PERMISSION_GRANTED) {
554+
Toast.makeText(getApplicationContext(), R.string.toast_no_permissions, Toast.LENGTH_LONG).show();
545555

546-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
547556
ActivityCompat.requestPermissions(MainActivity.this, new String[]{
548557
Manifest.permission.READ_MEDIA_AUDIO,
549558
Manifest.permission.READ_MEDIA_IMAGES,
550559
Manifest.permission.READ_MEDIA_VIDEO
551560
}, 0);
552-
} else {
553-
ActivityCompat.requestPermissions(MainActivity.this, new String[]{
554-
Manifest.permission.READ_EXTERNAL_STORAGE
555-
}, 0);
556-
}
557-
} else {
558-
final Intent intent = new Intent()
559-
.setType("*/*")
560-
.setAction(Intent.ACTION_OPEN_DOCUMENT)
561-
.addCategory(Intent.CATEGORY_OPENABLE);
562561

563-
activityResultLauncher.launch(Intent.createChooser(intent, getString(R.string.dialog_select_file)));
562+
return;
563+
}
564564
}
565+
566+
final Intent intent = new Intent()
567+
.setType("*/*")
568+
.setAction(Intent.ACTION_OPEN_DOCUMENT)
569+
.addCategory(Intent.CATEGORY_OPENABLE);
570+
571+
activityResultLauncher.launch(Intent.createChooser(intent, getString(R.string.dialog_select_file)));
565572
}
566573
}

0 commit comments

Comments
 (0)