Reputation: 1293
I have the following code to open a folder in Android, and although I see a lot of posts mentioning it works I am unable to get it working.
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
File f = new File(Environment.getExternalStorageDirectory(),"myFolder");
Uri uri = Uri.fromFile(f);
intent.setDataAndType(uri, "*/*");
startActivity(Intent.createChooser(intent, "Open folder"));
It just opens the root folder (in this case, /storage/sdcard and not /storage/sdcard/myfolder).
Anyone knows why?
thanks
Upvotes: 1
Views: 524
Reputation: 1007534
ACTION_GET_CONTENT
is not documented to use the Uri
portion of an Intent
. While there may be some apps with activities that support ACTION_GET_CONTENT
, many will not.
Moreover, Android does not really work with "folders", and so there will not necessarily be any app on a device that will allow you to browse arbitrary stuff.
You are welcome to use the Storage Access Framework on Android 4.4+, which is Google's approach to dealing with a central system UI for the users browsing content from multiple sources.
Or, there are plenty of file and directory picker libraries for Android.
Upvotes: 1