美文网首页
android动态请求权限

android动态请求权限

作者: 张利锋 | 来源:发表于2021-11-23 10:42 被阅读0次
/**
     * 请求授权
     */
    private void requestPermission() {
        List<String> permissionList = new ArrayList<>();
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            permissionList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
        }

        if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            permissionList.add(Manifest.permission.READ_EXTERNAL_STORAGE);
        }

        if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            permissionList.add(Manifest.permission.CAMERA);
        }

        if (!permissionList.isEmpty()) { //表示未授权时
            //进行授权
            ActivityCompat.requestPermissions(this, permissionList.toArray(new String[0]), 1);
        }
    }

相关文章

网友评论

      本文标题:android动态请求权限

      本文链接:https://www.haomeiwen.com/subject/grcwtrtx.html