androidbroadcastreceiverfingerprintandroid-usb

Android external fingerprint USB always returns false on USB permission


I have problem with Futronic fingerprint usb device on Android 10 & 11. The code

intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)

always return false when I press the OK button on permission dialog. I have old an android 5 device, it works OK.

Here is the code from their SDK (UsbDeviceDataExchangeImpl.java), included as module on Android Studio

    public UsbDeviceDataExchangeImpl( Context ctx, Handler trg_handler )
    {
        context = ctx;
        handler = trg_handler;
                
        mDevManager = (UsbManager)ctx.getSystemService(Context.USB_SERVICE);
        mPermissionIntent = PendingIntent.getBroadcast(ctx, 0, new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_IMMUTABLE);
        
        IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
        context.registerReceiver(mUsbReceiver, filter);
    }


    private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {

        public void onReceive(Context context, Intent intent)
        {
            String action = intent.getAction();
            if (ACTION_USB_PERMISSION.equals(action))
            {
                synchronized (mPermissionIntent)
                {
                    UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);

                    if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) 
                    {
                        if(device != null)
                        {
                            usb_ctx = OpenDevice(device);
                        }
                        
                        handler.obtainMessage(MESSAGE_ALLOW_DEVICE).sendToTarget();
                    } 
                    else
                    {
                        handler.obtainMessage(MESSAGE_DENY_DEVICE).sendToTarget();
                    }
                                        
                }
                
            }
        }
    };

Are there any extra permission settings for Android 10 & 11 for external usb device ?

Thank you.


Solution

  • Might be the same issue: AndroidStudio USB: EXTRA_PERMISSION_GRANTED returns false - always

    Changing PendingIntent.FLAG_IMMUTABLE to PendingIntent.FLAG_MUTABLE helped in my case.