I want to use a usb device in the following code. It successfully lists the usb devices and iterates over them. In the following code the object "device" is the usbdevice that i need to open. Everything seems Ok except the OpenDevice() method that always returns a null value!
[Activity(Label = "TestApp", MainLauncher = true, Icon = "@drawable/icon")]
[IntentFilter(new[] {UsbManager.ActionUsbDeviceAttached})]
[MetaData(UsbManager.ActionUsbDeviceAttached, Resource = "@xml/device_filter")]
public class MainActivity : Activity
{
int count = 1;
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
UsbManager manager = (UsbManager)GetSystemService(Context.UsbService);
UsbDevice device = null;
foreach (var dev in manager.DeviceList)
{
if (dev.Value.VendorId == 5401)
{
device = dev.Value;
}
}
var connection = manager.OpenDevice(device);
// Read some data! Most have just one port (port 0).
}
The device_filter.xml contains the following lines:
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<usb-device product-id="8704" vendor-id="5401" />
</resources>
When I tried bool hasPermision = manager.HasPermission(device); I saw that hasPermission is false. Could anybody tell me How can I grant permission for opening a usb device in xamarin? Thanks for any help.