Android Tutorial Android Usb Host Tutorial - AdbTest

Status
Not open for further replies.

axelbarry

New Member
Good afternoon Erel, first of all, many compliments for the forum, it's full of useful information and tips...it's great!

Referring to your statement:


Only Android 3.1 and above support USB host mode: USB Host | Android Developers

There is a back port for the accessory mode for Android 2.3.4.


I have seen a couple of devices, based on 2.3.5, that have the OTG interface (can support both Host and Peripherals mode).

In this case, do you think that the interface is just not called in the proper way or there is something that allows host mode also in this version?
 

agraham

Expert
Licensed User
Longtime User
I don't think that OTG support is equivalent to host mode.
Actually I think that it is. However the backport mentioned above is for Accessory mode in which the device acts as a USB slave. However USB Accessory | Android Developers states
This add-on library is a thin wrapper around the android.hardware.usb accessory APIs and does not support USB host mode
USB host mode is only officially supported in Android 3.1 and higher. If a device running Android below version 3.1 supports host mode then it will have been added by the device OEM and as Erel states will probably only support OS recognised things like mice, keyboards and mass storage.
 

axelbarry

New Member
Thank you very much guys.

Your statements are very clear.

Just to summarize: in case the host mode is supported by a pre 3.1 device (to read mass storage or any common HID), this doesn't mean that it supports all the methods of USB Host APIs...right?

...it is not always enough to have the device able to read mass storage or support OTG mode...

Have a nice week end guys...and thank you again!
 

krzyszp

Member
Licensed User
Longtime User
As I mention before, I tried to get data from Radioactivity detector (USB HID device). Another application recognise it as:
05df:16c0
obdev.at radioactiveathome.org GRS
But your example application doesn't recognise it at all. This happened because my device are HID device?
Can you help me, how to send requests and get answers from it, please?
 

pleth

New Member
Hi

I have a project, I would like to read and write on an USB key connected with a OTG cable on an Android device. Is it possible and easy using Basic4Android ?

Thanks. :sign0104:
 
Last edited:

tonga

Member
Licensed User
Longtime User
Hi Erel,
I'm using well this example to send a string from tablet to a microcontroller, but I'm not able to read the string that the microcontroller send to tablet. Using the debug breakpoint I see that something arrives to tablet... Can you help me?
Thanks!
 

MotoMusher

Active Member
Licensed User
Longtime User
Are there any settings I need to change on my phone for this? I am trying to access a gps, and not getting any responses from either:

B4X:
    Dim usbaccessories() As UsbAccessory
    usbaccessories = manager.GetAccessories
    For i = 0 To usbaccessories.Length - 1
        Log("zzzz")
    Next
  
    Dim usbdevices() As UsbDevice
    usbdevices = manager.GetDevices
  
    'Iterate over devices and find the correct one
    For i = 0 To usbdevices.Length - 1
        Log("aaa")
    Next

I have tried the GPS in both standard and mass storage mode

I also tried connecting to another android phone and same deal. USB hub is plugged into a computer, and the computer can see all 3 devices connected to hub
 
Last edited:

kiki78

Active Member
Licensed User
Longtime User
First, thank you Erel for this library.

I develop custom USB device and it work's generally fine.
My problem is when I'm connected to my device and disconnect USB cable. Some time I can't reconnect correctly.
The problem is enumeration seem's doesn't work.
I need to reboot tablet to retrieve connection.

I read http://developer.android.com/guide/topics/connectivity/usb/host.html and it is recommended to call releaseInterface() and close() but I never found it in library. May you add it in future release ?

I try BroadcastReceiver library from Xverhelst, with "android.hardware.usb.action.USB_DEVICE_DETACHED" action, and this work fine to detect disconnection of my device. So I expect that correct software disconnection solve my problem.

Regards
 

kiki78

Active Member
Licensed User
Longtime User
Sorry I miss this since I use synchronous communication !
Instead of UsbDevice.StopListening, I use UsbDevice.CloseSynchronous and this seems to work.
When I disconnect OTG cable on tablet side all work fine.
If I disconnect on device side and reconnect I obtain "USB High power connected" message, but this is solve if I disconnect on tablet size.
I expect this help.

Regards
 

3394509365

Active Member
Licensed User
Longtime User
hello, I can not find the device. Having said that I place the log sdk 19 and Basic4 v 3.2 with windows 7
 

3394509365

Active Member
Licensed User
Longtime User
hello, I can not find the device. Having said that I place the log sdk 19 and Basic4 v 3.2 with windows 7
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…