android – permission for storage that works with all devices-ThrowExceptions

Exception or error:

I have given the permission on the manifest
and given runtime permision for 6.0+
But still crashes with some devices….so i need a code for permission that works for all devices
kitkat+ to 10

private void checkpermission() {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, MY_WRITE_REQUEST_CODE);
        }

}

How to solve:

You can use this Dexter Library. I think dexter is a better library for runtime permission and it’s work for all devices.

Leave a Reply

Your email address will not be published. Required fields are marked *