Leverage Kotlin API for Android runtime permissions
Lightweight library to simplify the process of requesting permissions.
requirePermission
.
withPermission
.
requirePermission(Manifest.permission.CAMERA)
camera.start()
// or
withPermission(Manifest.permission.CAMERA) { isGranted ->
if (isGranted) {
camera.start()
}
}
repositories {
google()
mavenCentral()
}
dependencies {
compile 'com.hendraanggrian.appcompat:dangerous:0.1'
}
To force user open Settings app, provide the second DSL.
withPermission(Manifest.permission.CAMERA, { settingsIntent ->
AlertDialog.Builder(this)
.setTitle("Permission Denied")
.setMessage("Need to be enabled manually.")
.setPositiveButton("Go to Settings") { _, _ ->
startActivity(settingsIntent)
}
}) { isGranted ->
if (isGranted) {
camera.start()
}
}