Android Question SDK 31 and USBserial.RequestPermission

yo3ggx

Active Member
Licensed User
Longtime User
Hello,

As already mentioned in another thread, with targetSdkVersion="31" (mandatory for Play Store updates after 1st or November), I get the following error when trying to request permission for USBserial.

Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.

As suggested in another thread, I've updated Core internal library to 18.11 (still showing as 18.10 in the IDE), but no success.

There is any other possibility to solve this?

Thank you.
 

yo3ggx

Active Member
Licensed User
Longtime User
The error appears in the USBserial library in the line
'manager.requestPermission(usbDevice, PendingIntent.getBroadcast((Context)BA.applicationContext, 0, new Intet'
.
B4X:
 public void RequestPermission(int paramInt) {
    byte b = 1;
    UsbManager usbManager = (UsbManager)BA.applicationContext.getSystemService("usb");
    HashMap hashMap = usbManager.getDeviceList();
    if (hashMap.size() > 0)
      for (UsbDevice usbDevice : hashMap.values()) {
        if (b++ == paramInt) {
          usbManager.requestPermission(usbDevice, PendingIntent.getBroadcast((Context)BA.applicationContext, 0, new Intent("com.android.example.USB_PERMISSION"), 0));
          return;
        } 
      }  
    UsbAccessory[] arrayOfUsbAccessory = usbManager.getAccessoryList();
    if (arrayOfUsbAccessory != null)
      usbManager.requestPermission(arrayOfUsbAccessory[0], PendingIntent.getBroadcast((Context)BA.applicationContext, 0, new Intent("com.android.example.USB_PERMISSION"), 0)); 
  }
 
Last edited:
Upvote 0

yo3ggx

Active Member
Licensed User
Longtime User
No more errors. Now is working perfect with targetSdkVersion="31". Thanks a lot.
Initially tried to replace USBserial library with felUSBserial, but same errors occurs with that library too.
I will open another thread for felUSBserial, as I have another app using it (USBserial does not allow me to use multiple interfaces for the same usbserial device, like for example CP2105).
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
USBserial does not allow me to use multiple interfaces for the same usbserial device, like for example CP2105).
I thought it did, but I could be wrong. It was modified by user @JeanlLC to accept multiple device.
and I modified his source to add the required flag. What version were you using?
 
Upvote 0

yo3ggx

Active Member
Licensed User
Longtime User
What version were you using?
Version 2.4, but now I'm using your version (2.5). I'm talking about using multiple interfaces from the same device as separate felUSBserial instances. CP2105 has 2 serial ports (interfaces) in a single USB device. I don't see any option in the USBSerial library to select a specific interface. More, USBserial lib does not allow me to control RTS and DTR pins directly like that.
B4X:
    Dim USBSerial1 as felUsbSerial
    ...
    Dim jo As JavaObject
    jo = USBSerial1
    jo.RunMethod("setDTR", Array(true))
    jo.RunMethod("setRTS", Array(true))
 
Upvote 0
Top