授予权限后权限被拒绝

时间:2019-08-28 14:03:30

标签: java android android-studio android-permissions

我目前在使用HiPermission库时遇到运行时权限问题。我正在要求用户授予读取/写入外部存储的权限,但是即使我接受了该权限,尝试时仍然会遇到此错误从图库中打开图像。当应用程序启动时,将进行权限检查以查看用户是否已接受该权限。要访问该图像,用户需要使用一个也具有权限检查的按钮

private boolean checkAllPermissions(){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            int permissionCheck = PackageManager.PERMISSION_GRANTED;
            String[] requestedPermissions = new String[]
                    {Manifest.permission.WRITE_EXTERNAL_STORAGE,
                     Manifest.permission.CAMERA};
            for (String permission : requestedPermissions) {
                permissionCheck = permissionCheck + ContextCompat.checkSelfPermission(getContext(), permission);
            }
            if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
                makeText(getActivity(),R.string.actvt_main_tst_request_permission_all, Toast.LENGTH_LONG).show();
                return false;
            }
        }
        return true;
    }

这是我得到的错误:

  

E / BitmapFactory:无法解码流:   java.io.FileNotFoundException:   /storage/emulated/0/Download/download.png(权限被拒绝)

这很奇怪,因为如果我重新启动应用程序,一切正常。

public void requestAllPermissions(){

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            List<PermissionItem> permissionItems = new ArrayList<PermissionItem>();
            permissionItems.add(new PermissionItem(Manifest.permission.CAMERA, "Camera", R.drawable.permission_ic_camera));
            permissionItems.add(new PermissionItem(Manifest.permission.WRITE_EXTERNAL_STORAGE, "Storage", R.drawable.permission_ic_storage));
            HiPermission.create(MainActivity.this)
                    .title("Welcome to App")
                    .msg(getString(R.string.permis_req))
                    .permissions(permissionItems)
                    .animStyle(R.style.PermissionAnimScale)
                    .checkMutiPermission(new PermissionCallback() {
                        @Override
                        public void onClose() {
                            Log.i(TAG, "onClose");
                            Toast.makeText(getApplicationContext(), "They cancelled our request", Toast.LENGTH_SHORT);
                        }

                        @Override
                        public void onFinish() {
                            Log.wtf("finished","finished");
                            Toast.makeText(getApplicationContext(), "All permissions requested completed", Toast.LENGTH_SHORT);
                            System.exit(0);
                        }

                        @Override
                        public void onDeny(String permission, int position) {
                            Log.i(TAG, "onDeny");
                        }

                        @Override
                        public void onGuarantee(String permission, int position) {
                            Log.i(TAG, "onGuarantee");
                        }
                    });
        }

0 个答案:

没有答案