Android Question how to get an usb storage path?

Pietro Pancino

Member
Licensed User
Longtime User
hi,

I need to read image from an external usb storage on an Asus Tinkerboard.
I tried to get the name of an external usb storage with the following get_device_list to extract the name. (manager.getdevices....).
I get the name in the nom_cle_usb string, it's seems to be ok: /dev/bus/usb/003/009/

But when I want to list file in root folder I got an java error telling that this a not a folder name.
When I use esexplorer i got 3009 as name for this usb storage, but I can get access anyway.

When I set the folder name with File.DirRootExternal&"/otomat_folder", it is ok.

I'am sure I'm making a big mistake but I don't understand where.

If any one have an idea...

:) Pietro


code:
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")

nom_cle_usb="no usb storage"
numero_port_com = 255

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 = "& fonction.converthex(usb_device.VendorId) & " " & getvendorname(usb_device.VendorId))
send_log("device productid = "& fonction.converthex(usb_device.ProductId))
send_log("device name = "&usb_device.DeviceName)
send_log("device id = "&fonction.converthex(usb_device.DeviceId))
send_log("device class = "&fonction.converthex(usb_device.DeviceClass))
send_log("device DeviceSubclass = "&fonction.converthex(usb_device.DeviceSubclass))
send_log("device InterfaceCount = "&fonction.converthex(usb_device.InterfaceCount))

If getvendorname(usb_device.VendorId) ="FTDI" Then
numero_port_com = i
End If

For a = 0 To usb_device.InterfaceCount - 1
Dim inter As UsbInterface
inter = usb_device.GetInterface(a)
send_log("device InterfaceClass = "&fonction.converthex(inter.InterfaceClass) &" "& geinterfaceclass(inter.InterfaceClass))
send_log("device InterfacesubClass = "&fonction.converthex(inter.InterfacesubClass))
If geinterfaceclass(inter.InterfaceClass) = "Mass storage" Then
nom_cle_usb=usb_device.DeviceName&"/"
End If
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 = fonction.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 = fonction.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

Sub get_folder()
Dim le_folder As String

le_folder = nom_cle_usb&"/"

Dim lst0 As List
lst0 = File.ListFiles(le_folder)
Log ("liste des fichier du dossier "&le_folder)

Dim nom As String
Dim nom_list As String

' t_folder.SingleLineLayout.Label.TextSize = 12
' t_folder.SingleLineLayout.Label.TextColor = Colors.black
' t_folder.SingleLineLayout.Label.Gravity = Gravity.LEFT
' t_folder.SingleLineLayout.Label.Height= 30
' t_folder.SingleLineLayout.ItemHeight = 30

For i = 0 To lst0.Size - 1
nom = lst0.Get(i)
If File.IsDirectory(le_folder , nom) = False Then
nom_list = nom
Else
nom_list = "<"&nom&">"
End If
Log (nom_list)
' t_folder.AddSingleLine(nom_list)

Next

End Sub
 
Top