Skip to content

Instantly share code, notes, and snippets.

@DiegoGSantos
Created March 1, 2019 02:48
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/11e12da743630bff48a30a3728f54274 to your computer and use it in GitHub Desktop.
Save DiegoGSantos/11e12da743630bff48a30a3728f54274 to your computer and use it in GitHub Desktop.
class Activity {
fun selectImage() {
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
getImage()
} else {
askPermission()
}
}
private fun askPermission() {
ActivityCompat.requestPermissions(activity, arrayOf<String>(Manifest.permission.WRITE_EXTERNAL_STORAGE), 1)
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// 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