Last active
September 3, 2017 00:09
-
-
Save anstaendig/55636adaa23cbfcc14711afeeac4b390 to your computer and use it in GitHub Desktop.
permissions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ask for permission to read storage | |
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) | |
!= PackageManager.PERMISSION_GRANTED) { | |
if (ActivityCompat.shouldShowRequestPermissionRationale(this, | |
Manifest.permission.READ_EXTERNAL_STORAGE)) { | |
// This will happen if the user previously denied the permission | |
requestPermissions() | |
} else { | |
// We need to check if it's the first time we ask because | |
// shouldShowRequestPermissionRationale returns false in that case. | |
// We set a boolean (shared prefs for example) to store if we are asking for the first time or not | |
if (isFirstTimeAskingPermission(Manifest.permission.READ_EXTERNAL_STORAGE)) { | |
firstTimeAskingPermission(Manifest.permission.READ_EXTERNAL_STORAGE, false) | |
// No explanation needed, we can request the permission. | |
requestPermissions() | |
} else { | |
// Permission disable by device policy or user denied permanently. Show dialog to | |
// redirect to application settings | |
showDialogToNavigateToApplicationSettings() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment