Android 获取动态权限时候用户选择不再提示后无法获取权限的问题

1.添加依赖  
implementation 'com.qw:soulpermission:1.1.8'

2.

SoulPermission.getInstance().checkAndRequestPermissions(
                        Permissions.build(Manifest.permission.RECORD_AUDIO
                        ),
                        new CheckRequestPermissionsListener() {
                            @Override
                            public void onAllPermissionOk(com.qw.soul.permission.bean.Permission[] allPermissions) {
                                //获取到权限写你要做的代码
                            }

                            @Override
                            public void onPermissionDenied(com.qw.soul.permission.bean.Permission[] refusedPermissions) {
                    //用户拒绝权限 并且不再提示 时候需要这样写
                                if (Build.VERSION.SDK_INT >= 23) {
                                    if (!ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.RECORD_AUDIO)) {
                                        new AlertDialog.Builder(MainActivity.this).setTitle("权限设置")//设置对话框标题
                                                .setMessage(
                                                        "获取麦克风权限失败," +
                                                                "将导致部分功能无法正常使用,需要到设置页面手动授权")//设置显示的内容
                                                .setPositiveButton("去授权", new DialogInterface.OnClickListener() {//添加确定按钮
                                                    @Override
                                                    public void onClick(DialogInterface dialog, int which) {//确定按钮的响应事件
                                                        //TODO Auto-generated method stub
                                                        Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                                                        Uri uri = Uri.fromParts("package", getApplicationContext().getPackageName(), null);
                                                        intent.setData(uri);
                                                        startActivity(intent);
                                                        dialog.dismiss();
                                                    }
                                                }).setNegativeButton("取消", new DialogInterface.OnClickListener() {//添加返回按钮
                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {//响应事件
                                                // TODO Auto-generated method stub
                                                dialog.dismiss();
                                            }
                                        }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                                            @Override
                                            public void onCancel(DialogInterface dialog) {
//                                            mRequestPermissionCallBack.denied();
                                            }
                                        }).show();//在按键响应事件中显示此对话框

                                    }
                                }
                            }
                        });

 

你可能感兴趣的:(Android,动态权限获取,拒绝权限提示,禁止权限提示处理)