How to mount a USB drive on Android Things?

末鹿安然 提交于 2019-11-28 12:53:34

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).

I think the only solution is to create a service in init.rc to be able to execute the script with root permisions on Boot. Apparently Android things doesnt have a solution right know. Something like:

on property:dev.bootcomplete=1

start bootcomplete_handler

service bootcomplete_handler /system/bin/sh /system/bin/bc_handler.sh

class late_start

user root

group root

disabled

oneshot

But dont know if this will work

In_va2

I have made an script that every 10 seconds if detects a usb storage units mounts it automatically, the only problem is to launch it on Boot, maybe this could help you, I have my post here: Execute Script on Boot Android Things

And the script:

while true; do

if [ "$( ls -l /dev/block/sd* | wc -l)" -ge 1 ];

then echo "partition available"

if [ "$( mount | grep  "usbAlv" -c)" -ge 1 ]; #if partition not mounted

then echo " Unit Mounted"

else

echo "not  mounted"


//if folder where we mount the partition doesnt exist

if [ !"$( ls -l /sdcard/usbAlv | wc -l)" -ge 1 ];

then mkdir /sdcard/usbAlv

fi

su root << EOSU

mount -t vfat -o rw /dev/block/sd* /sdcard/usbAlv

EOSU

fi

else

echo "not partition available"

fi

sleep 10;

done

Hope it helps, i guess now is the only posible way to do it programatically

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