• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

App Inventor How to use USBManager without always asking the user permissions?

Hello,

I'm developing an application that use a USB device. Each time the device is reconnected, i must ask the user permission to connect to it.
The problem is that the smartphone and the device should work without an user intervention. Sometimes, the USB connector move a little bit and all my application is blocked because the permission are not granted anymore...

I found some tips for older versions of Android (...) but nothing for API 27...

Someone have a solution or a workaround to use a USB device without the user permission ?

Thx
 
After an enumeration of the USB devices connected on the USB connector, I was requesting the USB permission with the function UsbManager.requestPermission(device, id) for a specific device.
If i remove the requestPermission() function, I receive a runtime error.
If i use the function hasPermission() of the class UsbManager before asking the permission, each time the USB device is disconnected, it forget that it was already granted...

I finally found a workaround with this documentation: https://developer.android.com/guide/topics/connectivity/usb/host#permission-d
I use now an Intent Filter that start my application when a USB device (matching with my filter) is connected. It automatically receive the permission and don't show a popup anymore.

It's not the best way because I have to initialize all again in the function onResume() each time my USB device is detected.
If you have other ideas, please let me know and i'll try it.
 
Back
Top Bottom