nift4
nift4

Reputation: 80

Opening Files/DocumentsUI via Intent given the Path

My code:

Uri selectedUri = Uri.parse("file:///sdcard/Music");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(selectedUri, "*/*");
intent.setType("*/*");
intent.setClassName("com.android.documentsui", "com.android.documentsui.files.FilesActivity");
startActivity(intent);

But its always opens only the Downloads tab, not Music on my sdcard.

Upvotes: 3

Views: 1945

Answers (1)

David B
David B

Reputation: 36

Action:
android.intent.action.VIEW

Data:
content://com.android.externalstorage.documents/document/primary%3ADownload%2FMyDir

Mime:
vnd.android.document/directory

Flags:
These don't seem to be critical

This intent will invoke DocumentsUI (and likely other file managers) and if you pick DocumentsUI it will open to the provided path. %3A for the first / and %2F for subsequent / as you nest into the file tree.

Cheers!

Upvotes: 2

Related Questions