Skip to content

Instantly share code, notes, and snippets.

@DiegoGSantos
Last active March 1, 2019 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DiegoGSantos/76506ab582404805ab422b9634c66971 to your computer and use it in GitHub Desktop.
Save DiegoGSantos/76506ab582404805ab422b9634c66971 to your computer and use it in GitHub Desktop.
class Activity {
val permissionManager: PermissionManager
fun selectImage() {
if (permissionManager.isStoragePermissionGranted(this)) {
getImage()
} else {
askPermission()
}
}
private fun askPermission() {
permissionManager.askForPermission(this)
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (permissionManager.isPermissionGranted(grantResults[0])) {
// Treat request granted
} else {
// Treat request denied
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment