parent
db9d341708
commit
19c605844d
5 changed files with 42 additions and 0 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,42 @@ |
||||
package com.project.survey.util |
||||
|
||||
import android.content.Context |
||||
import blankj.utilcode.util.ToastUtils |
||||
import com.hjq.permissions.OnPermissionCallback |
||||
import com.hjq.permissions.Permission |
||||
import com.hjq.permissions.XXPermissions |
||||
import java.lang.ref.WeakReference |
||||
|
||||
object PermissionsUtil { |
||||
|
||||
fun checkStoragePermission(context: Context, onGranted: () -> Unit) { |
||||
WeakReference(context).get()?.let { ctx -> |
||||
val permissions = arrayListOf(Permission.MANAGE_EXTERNAL_STORAGE) |
||||
if (XXPermissions.isGranted(ctx, permissions)) { |
||||
onGranted() |
||||
return |
||||
} |
||||
XXPermissions.with(ctx) |
||||
.permission(permissions) |
||||
.request(object : OnPermissionCallback { |
||||
override fun onGranted(permissions: MutableList<String>, allGranted: Boolean) { |
||||
if (allGranted) { |
||||
onGranted() |
||||
} |
||||
} |
||||
|
||||
override fun onDenied( |
||||
permissions: MutableList<String>, |
||||
doNotAskAgain: Boolean |
||||
) { |
||||
ToastUtils.showShort("请手动授予文件读写权限") |
||||
if (doNotAskAgain) { |
||||
XXPermissions.startPermissionActivity(ctx, permissions) |
||||
} else { |
||||
checkStoragePermission(ctx, onGranted) |
||||
} |
||||
} |
||||
}) |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue