Simple Android Directory picker - How? Simple Android Directory picker - How? android android

Simple Android Directory picker - How?


Try to use Intent.ACTION_OPEN_DOCUMENT_TREE

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP){     Intent i = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);     i.addCategory(Intent.CATEGORY_DEFAULT);    startActivityForResult(Intent.createChooser(i, "Choose directory"), 9999);}

And get the result Uri from onActivityResult data.getData()

@Overrideprotected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {    super.onActivityResult(requestCode, resultCode, data);    switch(requestCode) {        case 9999:            Log.i("Test", "Result URI " + data.getData());            break;    }}


There's an open source library that does directory chooser and open/save file activities as well. It can be found on GitHub at https://github.com/BoardiesITSolutions/FileDirectoryPicker.

Works on Android API Level 17 and above

Disclaimer: I wrote it