Android Question How to get an external usb disk drive...

Pietro Pancino

Member
Licensed User
Hi,
I'am working on a Tinkerboard under Android (like RPI), I'm writing an application that need to read and write text file on an external USB drive.
How can I have the path name of the usb drive, or anyway the path of existing drives?
Is there a way of getting the path list of present drives?
... :)
 

Pietro Pancino

Member
Licensed User
Thanks Erel,
I found the way, I use usbdevice , usbinterface and so on to get the usb class (0008 mass storage) with this info I have the full path.
B4X:
Sub get_device_list()
    clear_log
    If manager.GetDevices.Length = 0 Then
        send_log("No connected usb devices.")
    Else
        send_log("there is "& manager.GetDevices.Length & " devices connected")
 
        Dim usbdevices() As UsbDevice
        usbdevices = manager.GetDevices
 
        'Iterate over devices and find the correct one
        For i = 0 To usbdevices.Length - 1
            Dim usb_device As UsbDevice
            usb_device = usbdevices(i)
            '    Log(usb_device)
            'Iterate over interfaces
            send_log("<------------------ Device N°" & (i) & "------------------>")
            send_log("device vendorid          = "& converthex(usb_device.VendorId) & " " & getvendorname(usb_device.VendorId))
            send_log("device productid         = "& converthex(usb_device.ProductId))
            send_log("device name              = "&usb_device.DeviceName)
            send_log("device id                = "&converthex(usb_device.DeviceId))
            send_log("device class             = "&converthex(usb_device.DeviceClass))
            send_log("device DeviceSubclass    = "&converthex(usb_device.DeviceSubclass))
            send_log("device InterfaceCount    = "&converthex(usb_device.InterfaceCount))
     
            For a = 0 To usb_device.InterfaceCount - 1
                Dim inter As UsbInterface
                inter = usb_device.GetInterface(a)
                send_log("device InterfaceClass       = "&converthex(inter.InterfaceClass) &" "& geinterfaceclass(inter.InterfaceClass))
                send_log("device InterfacesubClass    = "&converthex(inter.InterfacesubClass))
            Next
        Next
    End If

End Sub

Sub getvendorname(inti As Int) As String
    Dim out_str As String
    Dim tst_str As String
    out_str = "?"
    tst_str = converthex(inti)
    If tst_str ="0403" Then    out_str ="FTDI"
    If tst_str ="046D" Then    out_str ="LOGITECH"
    If tst_str ="067B" Then    out_str ="PROLIFIC"
    Return out_str
End Sub

Sub geinterfaceclass(inti As Int) As String
    Dim out_str As String
    Dim tst_str As String
    out_str = "?"
    tst_str = converthex(inti)
    If tst_str ="0000" Then    out_str ="User class info"
    If tst_str ="0001" Then    out_str ="Audio"
    If tst_str ="0002" Then    out_str ="Communications and CDC Control"
    If tst_str ="0003" Then    out_str ="HID (Human Interface Device)"
    If tst_str ="0005" Then    out_str ="Physical"
    If tst_str ="0006" Then    out_str ="Image"
    If tst_str ="0007" Then    out_str ="Printer"
    If tst_str ="0008" Then    out_str ="Mass storage"
    If tst_str ="0009" Then    out_str ="CDC-Data"
    If tst_str ="000A" Then    out_str ="HUB"
    If tst_str ="000B" Then    out_str ="CDC-Data"
    If tst_str ="000D" Then    out_str ="Content Security"
    If tst_str ="000F" Then    out_str ="Personal Healthcare"
    If tst_str ="0010" Then    out_str ="Audio/Video Devices"
    If tst_str ="0011" Then    out_str ="Billboard Device Class"
    If tst_str ="0012" Then    out_str ="USB Type-C Bridge Class"
    If tst_str ="00DC" Then    out_str ="Diagnostic Device"
    If tst_str ="00EO" Then    out_str ="Wireless Controller"
    If tst_str ="00EF" Then    out_str ="Miscellaneous"
    If tst_str ="00FE" Then    out_str ="Application specific"
    If tst_str ="00FF" Then    out_str ="Vendor specific"
    Return out_str
End Sub
 
Last edited by a moderator:
Upvote 0
Top