Android Question [Things] How to mount USB drive in app?

Tem

Member
Licensed User
Longtime User
I need to write some data to text file on USB external drive.
Mounting USB stick in Android Things using ADB works fine:
In ADB shell:

B4X:
su
mkdir /mnt/usb
mount -t vfat -o rw /dev/block/sda1 /mnt/usb

All works only using superuser.

Any idea, how to mount USB stick in own app? No permissins to do this
Android Things is not rooted
 

Tem

Member
Licensed User
Longtime User
Hi Erel

Here is my code:

B4X:
Sub Button_prepare_Click
    Dim StdOut, StdErr As StringBuilder
    Dim Ph As Phone
    StdOut.Initialize
    StdErr.Initialize
   
    Ph.Shell("su", Null, StdOut, StdErr)
    Ph.Shell("mkdir /mnt/usb", Null, StdOut, StdErr)
    'Ph.Shell("mount ", "-t vfat -o rw" & "/" & "dev" & "/" & "block" & "/" & sda1 , StdOut, StdErr)
   
    Msgbox(StdErr.tostring, "Mount USB Stick")
End Sub

Running this, error appears:

Error occured
An error has occurred in sub:main_button_prepare_click (java line:671)
java.io.IOExcepton: Cannot run program "su":error=13, Permission denied

When only "mkdir /mnt/usb" command is executed, the error appears on Msgbox:

Mount USB Stick
mkdir: '/mnt/usb': Permission denied
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…