diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index bfa80725b..30ee60ac9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,8 +9,8 @@ android:anyDensity="true" /> - - + + = Build.VERSION_CODES.KITKAT) { + i = new Intent(Intent.ACTION_OPEN_DOCUMENT); + } else { + i = new Intent(Intent.ACTION_GET_CONTENT); + } i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("*/*"); @@ -408,6 +419,9 @@ public class FileSelectActivity extends Activity { @Override protected void onResume() { super.onResume(); + + // check for storage permission + checkStoragePermission(); // Check to see if we need to change modes if ( fileHistory.hasRecentFiles() != recentMode ) { @@ -421,6 +435,60 @@ public class FileSelectActivity extends Activity { fnv.updateExternalStorageWarning(); } + private void checkStoragePermission() { + // Here, thisActivity is the current activity + if (ContextCompat.checkSelfPermission(FileSelectActivity.this, + Manifest.permission.WRITE_EXTERNAL_STORAGE) + != PackageManager.PERMISSION_GRANTED) { + + // Should we show an explanation? + //if (ActivityCompat.shouldShowRequestPermissionRationale(FileSelectActivity.this, + // Manifest.permission.WRITE_EXTERNAL_STORAGE)) { + + // Show an explanation to the user *asynchronously* -- don't block + // this thread waiting for the user's response! After the user + // sees the explanation, try again to request the permission. + + //} else { + + // No explanation needed, we can request the permission. + + ActivityCompat.requestPermissions(FileSelectActivity.this, + new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, + MY_PERMISSIONS_REQUEST_EXTERNAL_STORAGE); + + // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an + // app-defined int constant. The callback method gets the + // result of the request. + //} + } + } + + @Override + public void onRequestPermissionsResult(int requestCode, + String permissions[], int[] grantResults) { + switch (requestCode) { + case MY_PERMISSIONS_REQUEST_EXTERNAL_STORAGE: { + // If request is cancelled, the result arrays are empty. + if (grantResults.length > 0 + && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + + // permission was granted, yay! Do the + // contacts-related task you need to do. + + } else { + + // permission denied, boo! Disable the + // functionality that depends on this permission. + } + return; + } + + // other 'case' lines to check for other + // permissions this app might request + } + } + @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu);