0

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.

Halil Ozel
  • 2,482
  • 3
  • 17
  • 32
Lorensius W. L. T
  • 1,734
  • 4
  • 19
  • 31

2 Answers2

4

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.

guest
  • 136
  • 2
0

enter image description here

The Android demo sets it to 0 and it can also work.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 30 '23 at 17:39