开发者

How to get `File` reference to external disk?

开发者 https://www.devze.com 2023-01-25 08:18 出处:网络
I would like to get in my file browser File reference开发者_如何学C to external disk not SD Card. I mean I know that there is method

I would like to get in my file browser File reference开发者_如何学C to external disk not SD Card. I mean I know that there is method

Environment.getExternalStorageDirectory();

But to my knowledge this will get reference to SD Card. But how to get external disk (say kind of USB storage attached to Android device)? You know that device can have both SD card and external USB stick attached to them.


But how to get external disk (say kind of USB storage attached to Android device)?

Android does not support this. If particular devices do, you would have to ask their manufacturers what they recommend.


In the end I have selected following solution: 1) Enlisting all existing roots using:

File[] roots=File.listRoots();

2) check presense among those roots standard ones, i.e.

File phoneRoot=new File("//");
File sdRoot=Environment.getExternalStorageDirectory();

3) If there are some extra ones - treat them as those additional external disks/sticks

I think it's best solution, since no hacks, everything is standard and this covers possible future extensions.

0

精彩评论

暂无评论...
验证码 换一张
取 消