Skip to content

Instantly share code, notes, and snippets.

@akshaymukadam
Created August 18, 2019 08:53
Show Gist options
  • Save akshaymukadam/df2d06356ac24cb9c2bd1856e2b2f79a to your computer and use it in GitHub Desktop.
Save akshaymukadam/df2d06356ac24cb9c2bd1856e2b2f79a to your computer and use it in GitHub Desktop.
Permission Check request permission
if (ContextCompat.checkSelfPermission(this, $PERMISSION$)
!= PackageManager.PERMISSION_GRANTED) {
// Permission is not granted
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
$PERMISSION$)) {
TODO("Show Explainantion if needed")
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
arrayOf($PERMISSION$),
$REQUESTCODE$)
}
} else {
// Permission has already been granted
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment