Created
March 1, 2019 02:48
-
-
Save DiegoGSantos/11e12da743630bff48a30a3728f54274 to your computer and use it in GitHub Desktop.
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
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