Code for check storage permission in android.

Total Post:24

Points:168
 723  View(s)
Ratings:
Rate this:

Code for check storage permission in android.

  1. Post:24

    Points:168
    Re: Code for check storage permission in android.

    Code for storage permission

        public void checkForStoragePermission(){

            if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)    != PackageManager.PERMISSION_GRANTED) { 

                // Permission is not granted

                // Should we show an explanation

                if (ActivityCompat.shouldShowRequestPermissionRationale(this,     Manifest.permission.READ_EXTERNAL_STORAGE)) { 

                    // Show an explanation to the user *asynchronously* -- don't block

                    // this thread waiting for the user's response! After the user

                    // sees the explanation, try again to request the permission.

                    ActivityCompat.requestPermissions(this,        new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 

                            MY_PERMISSIONS_REQUEST_READ_STORAGE);

                }

            } else {

                Toast.makeText(this, "Permission granted", Toast.LENGTH_SHORT).show();

            }

            if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)      != PackageManager.PERMISSION_GRANTED) { 

                // Permission is not granted

                Toast.makeText(this, "Permission needed to read images", Toast.LENGTH_LONG).show();

            }

        }


Answer