问题
Using Android 6.0.1, API 23,
How do you get a USB-stick connected to your Android-phone being visible in the SAF picker that displays all matching document providers (including your USB-stick) ?? Moreover how to set-up SAF in order to create files and folders on the USB portable-storage ??
From the SAF-documentation, I tried:
public void performFileSearch() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
// in my case, showing only text-files is enough, therefore I guess the type is as follows:
intent.setType("text/plain");
startActivityForResult(intent, READ_REQUEST_CODE);
}
But the USB portable-storage is not part of the picker's choices...
What am I missing ? Is there an example project that shows the necessary steps ?
@CommonsWare: Here the desired screenshot:
回答1:
I just found a solution to the problem:
Having the SAF-client APP started (as found here) - including my tiny change inside performFileSearch()
(i.e. intent.setType("text/plain");
instead of what it was in the original DevBytesesample, intent.setType("image/*");
, the solution is as follows:
If you go into "Settings" (i.e. three vertical dots), you can select: "Show internal storage" - and this is it !!
After that connecting any USB-stick shows up as desired in the ContentProvider picker of SAF (see screenshot below) !
...no idea why an exterally connected USB-stick goes through as "internal storage" ??? (if somebody knows an answer to that mystery, I highly appreciate it !)... Anyway, happy to finally see the USB-flash appearing !!
来源:https://stackoverflow.com/questions/38942598/how-does-saf-storage-access-framework-recognize-your-usb-stick