I recently started writing on Xamarin, and I've got some problems with writing code to look at the devices attached to my host.
I've read the SDK documentations, and all the docs are written in java. I'm trying to change java into C#, and I coded this to find the devices attached:
UsbManager manager = (UsbManager)GetSystemService (Context.UsbService);
display.Text += " /n inizializzo il manager";
display.Text += "numero dispositivi: ";
display.Text += manager.DeviceList.Count;
With "usb manager" app I can see all the usb attached, there are 3. But with this code it appears to be 0 usb attached.
I don't understand why.
USB-C, explained This means that it can be a standard connector for both computers and phones, as well as other devices like game consoles. Some popular devices that use USB-C cables are the Nintendo Switch, MacBook Pro, and Samsung Galaxy line of phones.
To change USB preferencesConnect a USB cable to your device. Drag down the status bar, and then tap Android System next to (USB icon). Tap Tap for more options, and then select an option.
USB Type-C is a connector for delivering data and power to and from the phone. Most of the USB ports are built on a second-generation USB 3.1 standard that can deliver data at speeds of up to 10Gbps. In USB Type-C, both ends of the USB cable are the same, thereby enabling the reverse plug orientation.
Well it looks like you've already solved this one, I may have some additional tips for you though. First of all like you've found out USB-host is only supported in Android 3.1 and higher versions. Second of all, you need to add the "uses-feature " to the android manifest.
<uses-feature android:name="android.hardware.usb.host" android:required="false" />
Be sure to include required="false" to make sure that your app can be installed and started on device that do not support USB-host (if usb-host is optional for your app).
Third you'd be surprised how many modern mobile devices do not support host mode yet and fourth, the USB-port needs to supply enough power for the attached usb-device. Fifth and last point: Android is not really suited for high-speed "real-time" usb-communications. Android has a nasty habit of pausing the whole system and collecting garbage before "unblocking" and moving on. If you're trying to send a lot of data via usb at a constant rate this can cause the buffer to fill up when Android pauses and GC's, and at the next read to the buffer you may find corrupted data. So be sure to watch your memory management when building an app that includes usb-communications! I've found that configuring the Xamarin GC bridge to "Tarjan" mode helps quite a bit in reducing GC-induced pauses, this might be specific to my app though.
Maybe not a great fit as an answer to your question, but I was feeling chatty ;). Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With