android6.0+多个权限申请问题
迷茫
迷茫 2017-04-17 17:20:04
0
1
508

单个权限申请比较简单:

//判断当前版本是否大于M
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            //判断当前Activity是否获得了该权限
            if (ContextCompat.checkSelfPermission(activity,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                //没有授权,判断权限申请是否曾经被拒绝过
                if (ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                    Toast.makeText(activity, "你曾经拒绝过此权限,需要重新获取", Toast.LENGTH_SHORT).show();
                    //进行权限请求
                    ActivityCompat.requestPermissions(activity,
                            new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                            EXTERNAL_STORAGE_REQ_CODE);
                } else {
                    //进行权限请求
                    ActivityCompat.requestPermissions(activity,
                            new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                            EXTERNAL_STORAGE_REQ_CODE);
                }
                可是多个权限申请要怎么写?
                判断是否获取改权限的Permission貌似一次只能判断一个,如果在这个地方添加其他权限的判断,系统只会判断一次,然后给出所有权限判断的结果,,,所以,多个权限申请问题该怎么做?
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(1)
阿神

Multiple permissions means filling in multiple new String[]{Permission A, Permission B} in the application array. Apply for multiple permissions. If one is rejected, it will be judged as none. So you need to handle it yourself at the callback point

public void onRequestPermissionsResult(int requestCode, String[] permissions, int[]         grantResults)

Similarly judge the permissions one by one through the String[] array.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template