Skip to content
Permalink
Browse files

ANDROID: Ask for external storage access onCreate()

This is a quick fix, it needs to be improved upon

With this fix on devices with API >= Marshmallow (6.0.1) the ScummVM app will ask for the permission during runtime onCreate(),
and not only when trying to browse the list of folders and files.
However, it is only a quick fix, because the original behavior will still kick in and the prompt to Quit because no SD Card was detected will be displayed anyway.
So even if the user grants access during runtime, they will still be forced to exit the app and will have to relaunch.
  • Loading branch information...
antoniou79 committed Oct 7, 2019
1 parent eabb818 commit bd969478f8f90f845e05d9f0089c3a9ec50165d1
Showing with 7 additions and 1 deletion.
  1. +7 −1 backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java
@@ -193,6 +193,12 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.main);
takeKeyEvents(true);

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);
}

// This is a common enough error that we should warn about it
// explicitly.
if (!Environment.getExternalStorageDirectory().canRead()) {
@@ -333,7 +339,7 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in
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)
Toast.makeText(this, "Until permission is granted, some storage locations may be inaccessible!", Toast.LENGTH_SHORT)
.show();
}
break;

0 comments on commit bd96947

Please sign in to comment.
You can’t perform that action at this time.