How to get read external storage permissions? How to get read external storage permissions? android android

How to get read external storage permissions?


You have asked the permission from the code , but you are probably forgetting to add this permission tag in the manifest file

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>


Android introduce runtime permission from Marshmallow OS, so we need to implement runtime permission with Manifest permission. if CompileSdkVersion = 23

You can ask permission when your screen open (in onCreate()) or click event of your button (Like -play Music )

use this method for check runtime Permission is enable or not

 private static final int READ_STORAGE_PERMISSION_REQUEST_CODE = 41; public boolean checkPermissionForReadExtertalStorage() {    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {        int result = context.checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE);        return result == PackageManager.PERMISSION_GRANTED;    }    return false; }

if it return false then call below method, it will show a dialog for permission

 public void requestPermissionForReadExtertalStorage() throws Exception {        try {            ActivityCompat.requestPermissions((Activity) context, new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE},                    READ_STORAGE_PERMISSION_REQUEST_CODE);        } catch (Exception e) {            e.printStackTrace();            throw e;        }    }