Sdk 34 WRITE_EXTERNAL_STORAGE not working

29 views Asked by At

I changed to READ_MEDIA_IMAGES,READ_MEDIA_VIDEO,READ_MEDIA_AUDIO and write the code and give all permissions and also not working enter image description here enter image description here

` @RequiresApi(api = Build.VERSION_CODES.TIRAMISU) private boolean checkPermission() { int result = ContextCompat.checkSelfPermission(getApplicationContext(), WRITE_EXTERNAL_STORAGE); int result1 = ContextCompat.checkSelfPermission(getApplicationContext(), READ_MEDIA_AUDIO); int result2 = ContextCompat.checkSelfPermission(getApplicationContext(), MANAGE_EXTERNAL_STORAGE); int result3 = ContextCompat.checkSelfPermission(getApplicationContext(), CAMERA); int result4 = ContextCompat.checkSelfPermission(getApplicationContext(), READ_MEDIA_IMAGES); int result5 = ContextCompat.checkSelfPermission(getApplicationContext(), READ_MEDIA_VIDEO); int result6 = ContextCompat.checkSelfPermission(getApplicationContext(), ACCESS_MEDIA_LOCATION); int result7 = ContextCompat.checkSelfPermission(getApplicationContext(), MOUNT_UNMOUNT_FILESYSTEMS); return result == PackageManager.PERMISSION_GRANTED && result1 == PackageManager.PERMISSION_GRANTED; }

@RequiresApi(api = Build.VERSION_CODES.TIRAMISU)
private void requestPermission() {

    ActivityCompat.requestPermissions(this, new String[]{WRITE_EXTERNAL_STORAGE, CAMERA,MANAGE_EXTERNAL_STORAGE,READ_MEDIA_IMAGES,READ_MEDIA_VIDEO,READ_MEDIA_AUDIO,MOUNT_UNMOUNT_FILESYSTEMS,ACCESS_MEDIA_LOCATION}, PERMISSION_REQUEST_CODE);

}

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults); // Call super method
    switch (requestCode) {
        case PERMISSION_REQUEST_CODE:
            if (grantResults.length > 0) {

                boolean locationAccepted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
                boolean cameraAccepted = grantResults[1] == PackageManager.PERMISSION_GRANTED;

                if (locationAccepted && cameraAccepted)
                    Toast.makeText(this, "Permission Granted, Now you can access this app.", Toast.LENGTH_LONG).show();

                else {
                    Toast.makeText(this, "Permission Denied, You cannot use this app.", Toast.LENGTH_LONG).show();

                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                        if (shouldShowRequestPermissionRationale(WRITE_EXTERNAL_STORAGE)) {
                            showMessageOKCancel("You need to allow access to both the permissions",
                                    new DialogInterface.OnClickListener() {
                                        @RequiresApi(api = Build.VERSION_CODES.TIRAMISU)
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                                                requestPermissions(new String[]{WRITE_EXTERNAL_STORAGE, CAMERA,MANAGE_EXTERNAL_STORAGE,READ_MEDIA_IMAGES,READ_MEDIA_VIDEO,READ_MEDIA_AUDIO,MOUNT_UNMOUNT_FILESYSTEMS,ACCESS_MEDIA_LOCATION},
                                                        PERMISSION_REQUEST_CODE);
                                            }
                                        }
                                    });
                            return;
                        }
                    }

                }
            }


            break;
    }
}

private void showMessageOKCancel(String message, DialogInterface.OnClickListener okListener) {
    new AlertDialog.Builder(MainActivity.this)
            .setMessage(message)
            .setPositiveButton("OK", okListener)
            .setNegativeButton("Cancel", null)
            .create()
            .show();
}

}`

0

There are 0 answers