问题
I need the user to select a file of a custom filetype that they've dragged onto their android device from windows file explorer, but the internal storage option isn't available by default.
When I launch the intent using this:
var libraryIntent = new Intent(Intent.ActionOpenDocument);
libraryIntent.SetType("application/*");
_activity.StartActivityForResult(libraryIntent, (int)ActivityRequestCode.ImportFeatureCodeLibrary);
Android OS (5.1 and 6.0) shows the following screen:
The user has to know to go to the button in the top right and select the option to show internal file storage:
They have to click the hamburger again and only then does it show up in the list:
Is there a way to have this option show up in the list by default, or even better to have the user dropped into the "internal storage" file picker?
回答1:
You can add an extra to the intent
:
libraryIntent.PutExtra("android.content.extra.SHOW_ADVANCED", true);
As far as I know it's an undocumented extra, but it seams to work from API 19 to at least 26
回答2:
Please take a look at that library - Material File Picker
It allows showing a dialog with the specified path using .withPath(Environment.getExternalStorageDirectory().getAbsoluteFile())
.
The whole creation code:
new MaterialFilePicker()
.withActivity(this)
.withRequestCode(1)
.withFilter(Pattern.compile(".*\\.txt$")) // Filtering files and directories by file name using regexp
.withFilterDirectories(true) // Set directories filterable (false by default)
.withHiddenFiles(true) // Show hidden files and folders
.withPath(Environment.getExternalStorageDirectory().getAbsoluteFile())
.start();
来源:https://stackoverflow.com/questions/48193568/how-to-show-the-internal-storage-option-in-an-actionopendocument-intent-by-def