赞
踩
1.引入
//权限申请 implementation 'com.qw:soulpermission:1.1.6'
2.使用
- //动态获取权限
- private fun checkPermission() {
- //检查运行时权限 多权限
- var permissions = Permissions.build(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA)
-
- SoulPermission.getInstance().checkAndRequestPermissions(permissions, object : CheckRequestPermissionsListener {
- override fun onPermissionDenied(refusedPermissions: Array<out Permission>) {
- //反复的弹框用户可能会厌烦,大多数情况,我们这么封装就好:
- //SoulPermission提供栈顶Activity
- val activity = SoulPermission.getInstance().topActivity ?: return
- val permissionDesc = refusedPermissions[0].permissionNameDesc
-
- val showDialog = MaterialDialog.Builder(activity)
- .title("提示")
- .content(permissionDesc + "异常,请前往设置->权限管理,打开" + permissionDesc + "。")
- .positiveText("去设置")
- .onPositive { _, _ ->
- //去设置页
- SoulPermission.getInstance().goPermissionSettings()
- }.build()
- showDialog?.show()
- }
-
- override fun onAllPermissionOk(allPermissions: Array<out Permission>?) {
- //TODO 比如拍照 选择图片
-
- }
-
- })
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。