This library allows the usage of Kotlin with the new Android M permission model.
To use this library your minSdkVersion must be >= 14.
In your build.gradle :
repositories {
jcenter() // If not already there
}
dependencies {
compile 'cn.hchstudio:kpermissions:1.0.9'
}Create a KPermissions instance :
var kPermission: KPermission = KPermission(this) // where this is an Activity instanceExample : request the CAMERA permission
kPermission.requestPermission(arrayOf(Manifest.permission.CAMERA), {
Log.i(TAG, "isAllow---$it")
}, {
Log.i(TAG, "permission---$it")
})You can need add callback in 'onRequestPermissionsResult' :
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
kPermission.onRequestPermissionsResult(requestCode, permissions, grantResults)
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
}It can been use in Java.
Look at the sample app for more.
- add support in fragment
- add 'isDebug'
- add API 'startPermissionSetting()'
- Compatibility optimization