Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
[#105] add 'manage storage' permission
Browse files Browse the repository at this point in the history
  • Loading branch information
lfuelling committed Nov 9, 2020
1 parent 903a3dc commit c4e5088
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />

<application
Expand Down
26 changes: 24 additions & 2 deletions app/src/main/java/io/lerk/lrkFM/activities/file/FileActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.browser.customtabs.CustomTabsIntent;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
Expand Down Expand Up @@ -123,6 +124,11 @@ public class FileActivity extends ThemedAppCompatActivity {
*/
private static final int REQUEST_EXTERNAL_STORAGE = 1;

/**
* 0 if we have no permission.
*/
private static final int REQUEST_MANAGE_STORAGE = 1;

/**
* The rootfs path ('/').
*/
Expand All @@ -143,6 +149,16 @@ public class FileActivity extends ThemedAppCompatActivity {
*/
private static final String STATE_KEY_OP_CONTEXT_FILES = "state_current_op_files";

/**
* The permissions we need to do our job on Android R and higher.
*/
@RequiresApi(api = Build.VERSION_CODES.R)
private static final String[] PERMISSIONS_STORAGE_R = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.MANAGE_EXTERNAL_STORAGE
};

/**
* The permissions we need to do our job.
*/
Expand Down Expand Up @@ -1242,8 +1258,14 @@ void newFile(File file) {
* @param context the context
*/
public static void verifyStoragePermissions(Activity context) {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(context, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.MANAGE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(context, PERMISSIONS_STORAGE_R, REQUEST_EXTERNAL_STORAGE);
}
} else {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(context, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE);
}
}
}

Expand Down

0 comments on commit c4e5088

Please sign in to comment.