felHR85 / UsbSerial

Usb serial controller for Android
MIT License
1.78k stars 581 forks source link

new Intent(ACTION_USB_PERMISSION), 0); doesn't work in recent Android version #370

Open blotfi opened 4 months ago

blotfi commented 4 months ago

in UsbService.java

replace with

private void requestUserPermission() {
        Log.d(TAG, String.format("requestUserPermission(%X:%X)", device.getVendorId(), device.getProductId() ) );
        PendingIntent mPendingIntent = PendingIntent.getBroadcast(this, 0,
                new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_MUTABLE);
        usbManager.requestPermission(device, mPendingIntent);
    }
SerSerch commented 2 months ago
int flags = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ? PendingIntent.FLAG_IMMUTABLE : 0;
PendingIntent mPendingIntent = PendingIntent.getBroadcast(context, 0 , new Intent(Definitions.ACTION_USB_PERMISSION), flags);