Hi,
Am new to Xamarin development, have found some code from these forums that gets me to connect to a usb device (a thermal printer in this case).
Am trying to request permissions, but the request appears to be returning null.
var matchingDevice = usbManager.DeviceList.FirstOrDefault(item => item.Value.VendorId == vendorId && item.Value.ProductId == productId); if (usbManager.DeviceList.Count == 0) throw new Exception("No USB device connected"); if (matchingDevice.Value == null) throw new Exception("Device not found, try to configure it in settings."); // DeviceList is a dictionary with the port as the key, so pull out the device you want. I save the port too var usbPort = matchingDevice.Key; var usbDevice = matchingDevice.Value; // Get permission from the user to access the device (otherwise connection later will be null) if (!usbManager.HasPermission(usbDevice)) { try { //PendingIntent pi = PendingIntent.GetBroadcast(Forms.Context, 0, new Intent(ACTION_USB_PERMISSION), 0); PendingIntent pi = PendingIntent.GetBroadcast(MainActivity.Instance, 0, new Intent(ACTION_USB_PERMISSION), PendingIntentFlags.UpdateCurrent); usbManager.RequestPermission(usbDevice, pi); throw new Exception("Relaunch the application"); } catch (Exception ex) { throw new Exception($"{usbDevice.DeviceName} - {ex.Message}"); } }
When I run the app, I get the port number and the device number, but the popup for permissions says something like 'Allow connection to null'
Why would RequestPermission return null? Any help would be massively appreciated.
Many thanks