Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
- if (ActivityCompat.shouldShowRequestPermissionRationale(this,
- Manifest.permission.READ_EXTERNAL_STORAGE)) {
- // Show an expanation 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.
- AlertDialog.Builder adb = new AlertDialog.Builder(this);
- adb.setMessage("This app needs to read your External Storage/Gallery to provide the images and the music you're going to use in the video.").setPositiveButton("OK", null).create();
- adb.show();
- } else {
- // No explanation needed, we can request the permission.
- ActivityCompat.requestPermissions(this,
- new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
- MY_PERMISSIONS_REQUEST_READ_EXT_STORAGE);
- // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
- // app-defined int constant. The callback method gets the
- // result of the request.
- }
- }
- else
- {
- onCreateActual();
- }
- }
- private int MY_PERMISSIONS_REQUEST_READ_EXT_STORAGE = 102;
- @Override
- public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
- if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- Log.i("perms", permissions.length+"");
- int indexOfReadStorage = 0;
- for(int i = 0 ; i < permissions.length; i++)
- {
- Log.i("perms_len", permissions[i]);
- if(permissions[i].contains("READ_EXTERNAL_STORAGE"))
- {
- indexOfReadStorage = i;
- }
- }
- if (grantResults.length > 0 && grantResults[indexOfReadStorage] == PackageManager.PERMISSION_GRANTED) {
- // Permission Granted
- Log.i("read_ext_storage_perm", "granted");
- onCreateActual();
- } else {
- // Permission Denied
- Toast.makeText(this, "READ_EXT_STORAGE Denied", Toast.LENGTH_SHORT)
- .show();
- }
- }
- super.onRequestPermissionsResult(requestCode, permissions, grantResults);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement