Code example for UsbManager

Methods: requestPermission

0
 
    void RequestPermission() throws InterruptedException  { 
        PendingIntent mPermissionIntent = PendingIntent.getBroadcast(QtActivity.getQtActivityInstance(), 0, new Intent(ACTION_USB_PERMISSION), 0);
        IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
        QtActivity.getQtActivityInstance().registerReceiver(mUsbReceiver, filter);
        manager.requestPermission(device, mPermissionIntent);
        latch.await();
    } 
 
    public DashelSerial() throws InterruptedException { 
        manager = (UsbManager) QtActivity.getQtActivityInstance().getSystemService(Context.USB_SERVICE);
        device = (UsbDevice)  QtActivity.getQtActivityInstance().getIntent().getParcelableExtra(UsbManager.EXTRA_DEVICE);
        if(device == null) {
            HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
            Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
            while(deviceIterator.hasNext()){
                device = deviceIterator.next();
                if(device.getVendorId() == 0x0617 || device.getProductId() == 0x000a) {
                    RequestPermission(); 
                    break; 
                }