/KPermissions-kotlin

kotlin 之权限管理

Primary LanguageKotlin

KPermissions

This library allows the usage of Kotlin with the new Android M permission model.

Setup

To use this library your minSdkVersion must be >= 14.

Usage

Create a KPermissions instance :

var kPermission: KPermission = KPermission(this) // where this is an Activity instance

Example : 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.