Home > front end >  how to ask run time permission for WRITE_EXTERNAL_STORAGE in android
how to ask run time permission for WRITE_EXTERNAL_STORAGE in android

Time:12-09

Hi I am trying to get run time permission in android for WRITE_EXTERNAL_STORAGE. below code i have tried to ask run time permission but i am not getting permission

 private boolean checkPermissions() {
        if (ContextCompat.checkSelfPermission(getActivity(),
                Manifest.permission.ACCESS_FINE_LOCATION) !=
                PackageManager.PERMISSION_GRANTED) {
            if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
                    Manifest.permission.ACCESS_FINE_LOCATION)) {
                ActivityCompat.requestPermissions(getActivity(),
                        new String[]{(Manifest.permission.ACCESS_FINE_LOCATION)}, 1);
            } else {
                ActivityCompat.requestPermissions(getActivity(),
                        new String[]{(Manifest.permission.ACCESS_FINE_LOCATION)}, 1);
            }
           
        }
        return false ;
    }
    }

I am checking this code in Android 13 os version . Please help me what i am doing wrong how i can get run time permission in android 13 for WRITE_EXTERNAL_STORAGE .

CodePudding user response:

Hey Please read the android developer app target android 13 permission.

If your app targets Android 13 or higher and needs to access media files that other apps have created, you must request one or more of the following granular media permissions instead of the READ_EXTERNAL_STORAGE permission:

Type of media Permission to request Images and photos:- READ_MEDIA_IMAGES Videos:-READ_MEDIA_VIDEO Audio files:-READ_MEDIA_AUDIO

Android Developer Page Link

Happy Coding :)

  • Related