diff options
author | Eugene Sandulenko | 2019-09-27 00:11:54 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2019-09-27 00:22:20 +0200 |
commit | 3c92722db64e0e9af47b44e77a27371940f290f2 (patch) | |
tree | bbbdbe3e104829af0da8b54a65613ae4e4044915 /backends/platform/android/org | |
parent | 0481669b1f89f026786fb689169be9ff1f7b1466 (diff) | |
download | scummvm-rg350-3c92722db64e0e9af47b44e77a27371940f290f2.tar.gz scummvm-rg350-3c92722db64e0e9af47b44e77a27371940f290f2.tar.bz2 scummvm-rg350-3c92722db64e0e9af47b44e77a27371940f290f2.zip |
ANDROID: Request permissions to external storage
Diffstat (limited to 'backends/platform/android/org')
-rw-r--r-- | backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java b/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java index 6978f6e3b0..2d48dfa7b5 100644 --- a/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java +++ b/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java @@ -1,5 +1,7 @@ package org.scummvm.scummvm; +import android.Manifest; +import android.content.pm.PackageManager; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; @@ -33,6 +35,11 @@ public class ScummVMActivity extends Activity { private ClipboardManager _clipboard; + /** + * Id to identify an external storage read request. + */ + private static final int MY_PERMISSIONS_REQUEST_READ_EXT_STORAGE = 100; // is an app-defined int constant. The callback method gets the result of the request. + static { try { MouseHelper.checkHoverAvailable(); // this throws exception if we're on too old version @@ -53,6 +60,7 @@ public class ScummVMActivity extends Activity { } }; + private class MyScummVM extends ScummVM { public MyScummVM(SurfaceHolder holder) { super(ScummVMActivity.this.getAssets(), holder); @@ -158,7 +166,14 @@ public class ScummVMActivity extends Activity { @Override protected String[] getAllStorageLocations() { - return _externalStorage.getAllStorageLocations().toArray(new String[0]); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M + && checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED + ) { + requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, MY_PERMISSIONS_REQUEST_READ_EXT_STORAGE); + } else { + return _externalStorage.getAllStorageLocations().toArray(new String[0]); + } + return new String[0]; // an array of zero length } } @@ -306,6 +321,28 @@ public class ScummVMActivity extends Activity { } } + + @Override + public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { + switch (requestCode) { + case MY_PERMISSIONS_REQUEST_READ_EXT_STORAGE: + // If request is cancelled, the result arrays are empty. + if (grantResults.length > 0 + && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + // permission was granted + Log.i(ScummVM.LOG_TAG, "Read External Storage permission was granted at Runtime"); + } else { + // permission denied! We won't be able to make use of functionality depending on this permission. + Toast.makeText(this, "Until permission is granted, some folders might not be listed!", Toast.LENGTH_SHORT) + .show(); + } + break; + default: + break; + } + } + + @Override public boolean onTrackballEvent(MotionEvent e) { if (_events != null) |