Start by encapsulating a simple permission application framework by yourself, and learn the whole process of publishing open source libraries to Jitpack / Jcenter.
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.Simplation:XPermission:1.0.0'
}
XPermission.request(
this,
// 申请多个权限需要使用 `,` 隔开
Manifest.permission.CALL_PHONE,
Manifest.permission.CAMERA,
Manifest.permission.WRITE_EXTERNAL_STORAGE
) { allGranted, deniedList ->
/**
* allGranted:一个 boolean 类型的变量,若为 true ,则所有权限申请通过
* deniedList:一个 List 类型的变量,表示用户拒绝权限列表
*/
if (allGranted) {
call()
} else {
Toast.makeText(this, "You defined $deniedList", Toast.LENGTH_SHORT).show()
}
}
👤 Simplation
Github
: https://github.com/Simplation/Personal Blog
:http://www.simplation.wang/
Give a ⭐️ if this project helped you!