Android 动态申请权限

Android 动态申请权限,第1张

Android 动态申请权限
// 验证开启权限
public static void checkPermission(AppCompatActivity activity) {
    if (Build.VERSION.SDK_INT >= 23) {
        int checkPermission =
                ContextCompat.checkSelfPermission(activity, Manifest.permission.RECORD_AUDIO)
                        + ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_PHONE_STATE)
                        + ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)
                        + ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE)
                        + ContextCompat.checkSelfPermission(activity, Manifest.permission.PROCESS_OUTGOING_CALLS)
                        + ContextCompat.checkSelfPermission(activity, Manifest.permission.CAMERA)
                        + ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION)
                        + ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_COARSE_LOCATION)
                        + ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_PHONE_STATE);
        if (checkPermission != PackageManager.PERMISSION_GRANTED) {
            //动态申请
            ActivityCompat.requestPermissions(activity, new String[]{
                    Manifest.permission.RECORD_AUDIO,
                    Manifest.permission.READ_PHONE_STATE,
                    Manifest.permission.READ_EXTERNAL_STORAGE,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE,
                    Manifest.permission.PROCESS_OUTGOING_CALLS,
                    Manifest.permission.ACCESS_FINE_LOCATION,
                    Manifest.permission.ACCESS_COARSE_LOCATION,
                    Manifest.permission.CAMERA,
                    Manifest.permission.READ_PHONE_STATE}, 123);
            return;
        } else {
            return;
        }
    }
    return;
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5523193.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-13
下一篇 2022-12-13

发表评论

登录后才能评论

评论列表(0条)

保存