[Android / Play Store] Implement MANAGE_EXTERNAL_STORAGE permission

This commit is contained in:
Braden Farmer 2021-11-07 23:08:24 -07:00
parent a93a2e3366
commit 11de2ae1fe
4 changed files with 56 additions and 13 deletions

View File

@ -1,5 +1,6 @@
.gradle
.externalNativeBuild
.cxx
build
phoenix.iml
output.json

View File

@ -12,6 +12,7 @@
<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" />
<uses-permission android:name="android.permission.VIBRATE" />

View File

@ -25,8 +25,8 @@ allprojects {
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
compileSdkVersion 30
buildToolsVersion "30.0.3"
ndkVersion "22.0.7026061"
flavorDimensions "variant"
@ -72,7 +72,7 @@ android {
}
playStoreNormal {
minSdkVersion 21
targetSdkVersion 29
targetSdkVersion 30
versionCode getPlayStoreVersionCode()
versionName getPlayStoreVersionName()
@ -83,7 +83,7 @@ android {
}
playStorePlus {
minSdkVersion 26
targetSdkVersion 29
targetSdkVersion 30
versionCode getPlayStoreVersionCode()
versionName getPlayStoreVersionName()

View File

@ -3,10 +3,11 @@ package com.retroarch.browser.mainmenu;
import com.retroarch.browser.preferences.util.UserPreferences;
import com.retroarch.browser.retroactivity.RetroActivityFuture;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
@ -21,6 +22,7 @@ import android.Manifest;
import android.content.DialogInterface;
import android.app.AlertDialog;
import android.util.Log;
import android.widget.Toast;
/**
* {@link PreferenceActivity} subclass that provides all of the
@ -31,6 +33,7 @@ public final class MainMenuActivity extends PreferenceActivity
final private int REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS = 124;
public static String PACKAGE_NAME;
boolean checkPermissions = false;
boolean checkManageExternalStoragePermission = false;
public void showMessageOKCancel(String message, DialogInterface.OnClickListener onClickListener)
{
@ -64,12 +67,25 @@ public final class MainMenuActivity extends PreferenceActivity
List<String> permissionsNeeded = new ArrayList<String>();
final List<String> permissionsList = new ArrayList<String>();
final boolean requiresManageExternalStoragePermission =
getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.Q
&& Build.VERSION.SDK_INT > Build.VERSION_CODES.Q;
boolean shouldRequestManageExternalStoragePermission = false;
if (requiresManageExternalStoragePermission) {
if (!Environment.isExternalStorageManager()) {
shouldRequestManageExternalStoragePermission = true;
permissionsNeeded.add("Manage External Storage");
}
} else {
if (!addPermission(permissionsList, Manifest.permission.READ_EXTERNAL_STORAGE))
permissionsNeeded.add("Read External Storage");
if (!addPermission(permissionsList, Manifest.permission.WRITE_EXTERNAL_STORAGE))
permissionsNeeded.add("Write External Storage");
}
if (permissionsList.size() > 0)
if (permissionsList.size() > 0 || shouldRequestManageExternalStoragePermission)
{
checkPermissions = true;
@ -91,8 +107,24 @@ public final class MainMenuActivity extends PreferenceActivity
{
if (which == AlertDialog.BUTTON_POSITIVE)
{
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M)
{
if (requiresManageExternalStoragePermission) {
checkManageExternalStoragePermission = true;
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
intent.setData(Uri.fromParts("package", getPackageName(), null));
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
// Redirect to app info page instead, so that the user can manually grant the permission
String text = "Navigate to Permissions -> Files and media -> Allow all the time";
Toast.makeText(MainMenuActivity.this, text, Toast.LENGTH_LONG).show();
intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.fromParts("package", getPackageName(), null));
startActivity(intent);
}
} else {
requestPermissions(permissionsList.toArray(new String[permissionsList.size()]),
REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS);
@ -194,4 +226,13 @@ public final class MainMenuActivity extends PreferenceActivity
checkRuntimePermissions();
}
@Override
public void onTopResumedActivityChanged(boolean onTop) {
if(onTop && checkManageExternalStoragePermission) {
checkPermissions = false;
checkManageExternalStoragePermission = false;
checkRuntimePermissions();
}
}
}