How does SAF (storage access framework) recognize your USB-stick?

自闭症网瘾萝莉.ら 提交于 2019-12-12 01:14:19

问题


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

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