1

How can I access files on usb drive from my android app. Device is not rooted. I do not want to use storage access framework. Is it possible to get file path using android USB Host apis. In nexus devices and many other vendors', usb storage is not a mounted storage so it cannot be accessed normally.

Praveen Pandey
  • 409
  • 3
  • 20
  • 1
    The requirements and limitations of this have been covered numerous times before – Chris Stratton May 25 '16 at 20:22
  • Use the storage access framework on APIs > 19. For APIs < see older questions already asked here. USB Host Apis wont save you. – petey May 25 '16 at 20:22
  • @Chris: Can you share me a link where there is a correct answer for this. I am not able to find any workable answer. – Praveen Pandey May 25 '16 at 20:24
  • @petey: thanks for your comment. Actually I do not want to use SAF because of some functionalities of my app will get affected. I need some other solution. I can see ES File explorer can list files from usb storage, and they do not use SAF. I am wondering what apis have they used. – Praveen Pandey May 25 '16 at 20:27
  • 1
    Done. Keep in mind that stackoverflow is for specific questions. *It is explicitly not to be used to ask for code to use for a project*, and accessing a mass storage device via the host apis will require *a lot* of of code within your app. – Chris Stratton May 25 '16 at 20:37
  • @Chris: some confusions if you can clarify. When otg pen drive attached I saw LG mobiles are showing contents as normal sd card, in their gallary and other app. Few other mobiles detect it as external storage when but not showing contents in gallery. And all others are not detecting as external storage also. Can you please explain this. – Praveen Pandey Jun 23 '16 at 08:08
  • As explained at the link "Android" did not support this, but presumably despite that a given device manufacturer could add non-standard capabilities to a specific device. – Chris Stratton Jun 23 '16 at 14:19

1 Answers1

0

If the Android device supports USB Host mode, you need to have a USB OTG cable to connect to the flash drive. This cable has a resistor in line that signals to the USB controller on the Android device to switch to Host Mode.

These cables can be purchased from many online retailers.

Short answer is: No, your app alone cannot access the USB device.

Justin Pearce
  • 4,994
  • 2
  • 24
  • 37
  • Yes I am using USB OTG pendrive only. ES File explorer is able to detect my pendrive. So my app should also be able to read and list files, though I am not able to find how to make it work. – Praveen Pandey May 25 '16 at 20:27
  • @PraveenPandey The first link in my answer regarding USB Host goes to the Android API for handling USB Host mode. It might have the info you need. – Justin Pearce May 25 '16 at 20:30
  • Justin, I have gone through this. But here there isn't any information about how to list files. – Praveen Pandey May 25 '16 at 20:33
  • Indeed, the host APIs have no knowledge of mass storage protocol or filesystems. – Chris Stratton May 25 '16 at 20:34