0

I'm using the following code to get the list of all external storage devices either SDCard or USB connected via OTG

  List<String> paths = new ArrayList<String>();
    File directory = new File("/storage");

    File[] files = directory.listFiles();

It reads sdcard in all devices but the USB gets detected in some

What should i use?

1 Answers1

0

There are no filesystem paths that you can use on Android 4.4+, except those that are returned by getExternalFilesDirs(), getExternalCacheDirs(), and getExternalMediaDirs() (all plural, all on Context).

Ideally, you should be using the Storage Access Framework (e.g., ACTION_OPEN_DOCUMENT_TREE), as that provides the user with the greatest flexibility. However, you are no longer working with files and a filesystem, but rather with Uri values, reminiscent of working with Web services.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491