Android media viewer read permission


The Android media viewer read permission tutorial series describes how to implement permission to access external read storage for both marshmallow devices and older.

Get Code

The code can be found on github from the following instructions below Tag


or you can run this command

git clone –branch


This video describes how to import a project from github using android studio and also how to select a git tag.


Create a new android project

Add the external read storage permission to the AndroidManifest file

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

 Create a request id member to represent the read external storage permission request

    private final static int READ_EXTERNAL_STORAGE_PERMMISSION_RESULT = 0;

 Create a method to check whether the read external storage runtime permission has been granted or not

private void checkReadExternalStoragePermission() {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if(ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) ==
                    PackageManager.PERMISSION_GRANTED) {
                // Start cursor loader
            } else {
                if(shouldShowRequestPermissionRationale(Manifest.permission.READ_EXTERNAL_STORAGE)) {
                    Toast.makeText(this, "App needs to view thumbnails", Toast.LENGTH_SHORT).show();
                requestPermissions(new String[] {Manifest.permission.READ_EXTERNAL_STORAGE},
        } else {
            // Start cursor loader

 Implement the onRequestPermissionsResult method to check whether the external read storage request has been granted

    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        switch(requestCode) {
                if(grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    //Call cursor loader
                    Toast.makeText(this, "Now have access to view thumbs", Toast.LENGTH_SHORT).show();
                super.onRequestPermissionsResult(requestCode, permissions, grantResults);

 Call the checkReadExternalStoragePermission method from onCreate

protected void onCreate(Bundle savedInstanceState) {



Android media viewer read permission summary

A logical start to android application development is to ensure you have the correct permissions setup for any resources that your app will need.

In this case the android media thumbnail viewer requires access for reading files from storage.

So as well as providing the appropriate permission in the AndroidManifest file, runtime permissions were also setup in the main activity.


About The Author

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>