Search code examples
androidandroid-sdcardstorage-access-framework

ACTION_OPEN_DOCUMENT_TREE Shows Empty Recent List


I want to provide my application with Write Permission for SD Card. I am trying to use Storage Access Framework to get thoose perissions.

But when i start the Activity using the following code.

startActivityForResult(new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE), 42);

i am getting the following empty Recent list with no other option to select Internal Memory or SD Card in my Phone (Android Version 5.1.)

Phone Screenshot

Whereas the Emulator running Android 5.1 shows SD card memory.

Emulator Screenshot

Could anyone please suggest what is wrong? Because couple of other applications(ES Explorer,MP3 Editer) asked for permission in my phone where i was able to select the SD Card.


Solution

  • I had the same problem and solved it by adding an extra to the Document Tree intent.

    Intent intent = new Intent("android.intent.action.OPEN_DOCUMENT_TREE");
    intent.putExtra("android.content.extra.SHOW_ADVANCED", true);
    startActivityForResult(intent, REQUEST_CODE);