Android Question USB Serial Run Time Permission (USB Serial Permisison Dialog )

Microinvest

Member
Licensed User
Longtime User
Since Android 6 was introduced, apps might require various run time(dynamic) permission in order to allow different features. Currently B4A has Run Time permission, which allow app to ask user for run time permission, for example:
Code:
rp As RuntimePermissions
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)

We used this dynamic runtime permission, but Today we found out that USB Permission Dialog is not appear in Android 10. And since Usb permission is "called" from usbmanager, not from permission, I can't use runtimepermission library for that purpose (for example rp.hardware.usb.action.USB_DEVICE_ATTACHED is not a valid statement). And I need solution with runtime permission - I already use solutions like this for older Android versions:

We also, already use Usb filter in manifest, but since Android 10 Android USB Permission dialog, is not appearing anymore (we haven't tested Android 9, the dialog works until Android 8.1, and doesn't work with Android 10). Example from Manifest:

AddPermission(android.hardware.usb.action.USB_DEVICE_DETACHED)
AddPermission(android.hardware.usb.action.USB_DEVICE_ATTACHED)

B4X:
CreateResource(xml, device_filter.xml,
<resources>       
    <usb-device />   
</resources>
)
AddApplicationText(
<activity android:name=".main" >
   <intent-filter>
    <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
   </intent-filter> 
    <meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" android:resource="@xml/device_filter" />  
</activity>
)

Help will be appreciated, please, note it is about Android 10 Runtime permission (usb serial dialog) and NOT permissions, defined in the manifest.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
USB has nothing to do with the standard runtime permissions.

AddPermission(android.hardware.usb.action.USB_DEVICE_DETACHED)
AddPermission(android.hardware.usb.action.USB_DEVICE_ATTACHED)
This should be removed as these are not permissions.

Nothing has changed in Android 10, related to USB.
The device_filter.xml is not set correctly.

Example:
B4X:
CreateResource(values, device_filter.xml,
<resources>
<usb-device vendor-id="1921" product-id="21891"/>
<usb-device vendor-id="3468" product-id="316"/>
<usb-device vendor-id="4292" product-id="60000"/>
</resources>
)
 
Upvote 0

Microinvest

Member
Licensed User
Longtime User
It is set correctly for unknown vendor_id's - it was tested and works in Andorid 4.4.2, 4.4, 5, 6, 7, 8.1 - not tested in 9, and not working on 3 different models under Android 10. I'm also sure in OTG cable and usb device as well (I tested them with older android devices).

As for the filter, the id is not set by purpose, as we don't know in advance what type of connector/adapter and or OTG user will connect (vendor-id will depepend on the particular model). That's why I focused in the first post on the fact that code, manifest and filter are working without any issue.

So if there is no change from Android 10 regarding these matters, how do you think we can define device filter, in case we don't know in advance what are vendor_id's?

As for my run time permission questions, those topics made me to think in this direction:

Best Regards
 
Upvote 0
Top