@@ -538,29 +538,36 @@ public boolean onNavigationItemSelected(@NonNull final MenuItem item) {
538
538
}
539
539
540
540
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 ();
545
555
546
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
547
556
ActivityCompat .requestPermissions (MainActivity .this , new String []{
548
557
Manifest .permission .READ_MEDIA_AUDIO ,
549
558
Manifest .permission .READ_MEDIA_IMAGES ,
550
559
Manifest .permission .READ_MEDIA_VIDEO
551
560
}, 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 );
562
561
563
- activityResultLauncher .launch (Intent .createChooser (intent , getString (R .string .dialog_select_file )));
562
+ return ;
563
+ }
564
564
}
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 )));
565
572
}
566
573
}
0 commit comments