Android: Improve WRITE_EXTERNAL_STORAGE denial

This commit is contained in:
Ryan Meredith 2020-09-13 10:08:04 -04:00
parent b1fecbb71c
commit d643723d3a
4 changed files with 11 additions and 38 deletions

View File

@ -207,6 +207,8 @@ public final class MainActivity extends AppCompatActivity implements MainView
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults)
{
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == PermissionsHandler.REQUEST_CODE_WRITE_PERMISSION)
{
if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
@ -217,13 +219,9 @@ public final class MainActivity extends AppCompatActivity implements MainView
}
else
{
Toast.makeText(this, R.string.write_permission_needed, Toast.LENGTH_SHORT).show();
Toast.makeText(this, R.string.write_permission_needed, Toast.LENGTH_LONG).show();
}
}
else
{
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
/**

View File

@ -217,6 +217,8 @@ public final class TvMainActivity extends FragmentActivity implements MainView
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults)
{
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == PermissionsHandler.REQUEST_CODE_WRITE_PERMISSION)
{
if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
@ -226,14 +228,9 @@ public final class TvMainActivity extends FragmentActivity implements MainView
}
else
{
Toast.makeText(this, R.string.write_permission_needed, Toast.LENGTH_SHORT)
.show();
Toast.makeText(this, R.string.write_permission_needed, Toast.LENGTH_LONG).show();
}
}
else
{
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
private void buildRowsAdapter()

View File

@ -114,11 +114,11 @@ public class AfterDirectoryInitializationRunner
switch (state)
{
case EXTERNAL_STORAGE_PERMISSION_NEEDED:
Toast.makeText(context, R.string.write_permission_needed, Toast.LENGTH_SHORT).show();
Toast.makeText(context, R.string.write_permission_needed, Toast.LENGTH_LONG).show();
return true;
case CANT_FIND_EXTERNAL_STORAGE:
Toast.makeText(context, R.string.external_storage_not_mounted, Toast.LENGTH_SHORT).show();
Toast.makeText(context, R.string.external_storage_not_mounted, Toast.LENGTH_LONG).show();
return true;
default:

View File

@ -2,17 +2,12 @@ package org.dolphinemu.dolphinemu.utils;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.os.Build;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity;
import org.dolphinemu.dolphinemu.R;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
public class PermissionsHandler
@ -31,14 +26,9 @@ public class PermissionsHandler
if (hasWritePermission != PackageManager.PERMISSION_GRANTED)
{
if (activity.shouldShowRequestPermissionRationale(WRITE_EXTERNAL_STORAGE))
{
showMessageOKCancel(activity, activity.getString(R.string.write_permission_needed),
(dialog, which) -> activity.requestPermissions(new String[]{WRITE_EXTERNAL_STORAGE},
REQUEST_CODE_WRITE_PERMISSION));
return false;
}
// We only care about displaying the "Don't ask again" check and can ignore the result.
// Previous toasts already explained the rationale.
activity.shouldShowRequestPermissionRationale(WRITE_EXTERNAL_STORAGE);
activity.requestPermissions(new String[]{WRITE_EXTERNAL_STORAGE},
REQUEST_CODE_WRITE_PERMISSION);
return false;
@ -57,16 +47,4 @@ public class PermissionsHandler
return true;
}
private static void showMessageOKCancel(final FragmentActivity activity, String message,
DialogInterface.OnClickListener okListener)
{
new AlertDialog.Builder(activity, R.style.DolphinDialogBase)
.setMessage(message)
.setPositiveButton(android.R.string.ok, okListener)
.setNegativeButton(android.R.string.cancel, (dialogInterface, i) ->
Toast.makeText(activity, R.string.write_permission_needed, Toast.LENGTH_SHORT)
.show())
.show();
}
}