Android Question How to find USB Mass Storage - Usb Stick

ronovar

Active Member
Licensed User
I im developing videoview recorder and need to get to first detect USB Stick so that i can get usb path on witch will be record from videoview stream.

I im using this code (example taken from this forum) and could not figure out how can i find witch is USB Drive and what is location for writing on USB Flash Drive.

B4X:
'FIND - UsbDevice
Sub FindUsbDevice As Boolean
   Dim manager As UsbManager
   Dim usbdevices() As UsbDevice
   manager.Initialize
   usbdevices = manager.GetDevices
   
   For i = 0 To usbdevices.Length - 1
      Dim ud As UsbDevice
      ud = usbdevices(i)
      Log(ud)
   Next
End Sub

In Log Manager i im getting this:

(UsbDevice) UsbDevice[mName=/dev/bus/usb/001/002,mVendorId=1507,mProductId=1552,mClass=9,mSubclass=0,mProtocol=2,mInterfaces=[Landroid.os.Parcelable;@43bf98d0]
(UsbDevice) UsbDevice[mName=/dev/bus/usb/001/001,mVendorId=7531,mProductId=2,mClass=9,mSubclass=0,mProtocol=1,mInterfaces=[Landroid.os.Parcelable;@43bf91c8]
(UsbDevice) UsbDevice[mName=/dev/bus/usb/001/004,mVendorId=1507,mProductId=1831,mClass=0,mSubclass=0,mProtocol=0,mInterfaces=[Landroid.os.Parcelable;@43bfa0e0]
(UsbDevice) UsbDevice[mName=/dev/bus/usb/001/003,mVendorId=3141,mProductId=4361,mClass=0,mSubclass=0,mProtocol=0,mInterfaces=[Landroid.os.Parcelable;@43bf9cd8]

Product and Vendor ID is different for others USB Flash Drive (Different Manufacturer, Model etc.) so i can't use just to find Vendor and Manufacturer ID because it will not work on different USB Flash Drives.
 

ronovar

Active Member
Licensed User
Thanks Erel for replay ... i write this simple code

B4X:
'FIND - UsbStorage
Sub FindUsbDevice As String
   'CHECK - UsbStorage
   If (File.Exists("/storage/external_storage/sda1", "") = True) Then
       Return "/storage/external_storage/sda1"
   Else
       If (File.Exists("/storage/external_storage/sda2", "") = True) Then
          Return "/storage/external_storage/sda2"
      End If
     Return "Error"
   End If
End Sub

So my question is does on every android device if usb flash drive is inserted is on sda1 or sda2?

I try on two different android box devices and they have same sda1.
 
Upvote 0

ronovar

Active Member
Licensed User
Thanks Erel...i im getting using this code:

/storage/emulated/0/Android/data/b4a.example/files

this for output so i im currently staying at code above...if i find android device that have different storage location i will update code.
 
Upvote 0
Top