Lightweight library to simplify the process of requesting runtime permissions.
Powered by the newer Activity Result APIs,
so we no longer have to override onActivityResult()
.
- Blocking call with
requirePermission
, or use Kotlin DSL withwithPermission
. - Force user to open settings when the permission is always declined.
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()
}
}