How to Mount a Usb Drive on Android Things

How to mount a USB drive on Android Things?

ADB ONLY SOLUTION

Seem like as of now USB drives aren't mounted automatically. In order to make your code work I had to mount it manually.

As you can see (from /proc/partitions) in the /proc partition the USB drive is detected as sda.

ADB mounting

  • Make a directory to mount to

    mkdir /mnt/usb
  • Mount the device

    mount -t vfat -o rw /dev/block/sda1 /mnt/usb

Now you should be able to list (and manage) the files on the USB drive both via ADB and from within the app (/mnt/usb will also be logged).

Android Things filesystem

I'm didn't try it, but seems it's possible by the same way as in normal Android OS. To do this You should mount Your USB dongle into the filesystem somewhere e.g. in new folder /mnt/usb like in this answer of Onik or that project of Keval Patel:

Mount USB drive:

Plug you USB drive at any of the USB port in your Raspberry Pi.

Open adb shell by typing below command in terminal (Make sure your raspberry pi is connected via adb):

adb shell

Mount the USB drive by running below command in adb shell (Your USB drive should be formatted in FAT file system):

su mkdir /mnt/usb

mount -t vfat -o rw /dev/block/sda1 /mnt/usb

where

sda1 is the first partition of the first disk (sdb1 is the first partition of the second disk, etc.) and /mnt/usb - new folder for mounted USB dongle.

Then You can access to mounted USB dongle something like this way:

File usbDongleRoot = new File("/mnt/usb");

(or something like this).

Also take a look at this answer of JBA and that repo of Shaka Huang.

Using Android phone as USB Host to mount external drives to phone and accessing the memory of the external drive through phone

The only sure way of getting this done is to use API level above 12, otherwise a few phones may have support for usb host but most of them wont support it.
The reason being first of all you need hardware support for usb host, even if that is present the drivers needed might not be compiled into the kernel, i did some work while trying to implement usb host on nook color, even though it had hardware support, getting usb host working took almost 2 months and a dedicated app. So its not something you will be able to do for every device. A few might support it out of the box but even those would need root and lots more work for mounting drives and all that..
the DSLR camera also does it the same way look at the requirements

- Android device with ARMv7-A or newer CPU architecture (most 1ghz+ devices)
- Not rooted: Android 3.1 or higher with USB host kernel+API support
- Rooted: Android 2.3.1 or higher with USB host kernel support

These are the only devices that can support USB host.

How do I enable the ethernet over USB drivers on Android Things?

Seems You can't do it now: only when support of USB<->Ethernet devices will be implemented in Android Things or the source code of Android Things becomes available (then You can add Your USB driver support manually as You wrote).



Related Topics



Leave a reply



Submit