Getting Permission Denial Exception

Please check these questions too:
Android KitKat securityException when trying to read from MediaStore
Permission denial: opening provider

For the same problem on KitKat, I used this. It’s an option/workaround I had found from one of the Stack Overflow links, you will be able to select files from Downloads/Recent.

public static final int KITKAT_VALUE = 1002;

Intent intent;

if (Build.VERSION.SDK_INT < 19) {
    intent = new Intent();
    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.setType("*/*");
    startActivityForResult(intent, KITKAT_VALUE);
} else {
    intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("*/*");
    startActivityForResult(intent, KITKAT_VALUE);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == KITKAT_VALUE ) {
        if (resultCode == Activity.RESULT_OK) {
            // do something here
        }
    }
}

Reference:
Android Gallery on KitKat returns different Uri for Intent.ACTION_GET_CONTENT
http://developer.android.com/guide/topics/providers/document-provider.html#client

Leave a Comment