How to show the “internal storage” option in an ActionOpenDocument intent by default

▼魔方 西西 提交于 2020-01-02 04:11:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!