USB Host Mode - device access permission granted but not remembered

℡╲_俬逩灬. 提交于 2021-02-06 15:10:55

问题


I have a USB Host Mode application that works perfectly. I plug in the device, Android pops up the Allow the app APPNAME to access the USB device? permission request window, I check the Use by default for this USB device tick box and tap OK, then up comes my app and it communicates with the USB device perfectly.

BUT...

Then I unplug the device and plug it back in. Android pops up the Allow the app APPNAME to access the USB device? dialog again. WTH? I've already told Android to do this by default, so why is it asking me again?

This happens both with Icecream Sandwich 4.0.3 and Jellybean 4.1.

Ideally I want Android to remember I've granted permission for this particular USB device even after I've rebooted the Android device.

So why isn't Android remembering that I've granted permission?


回答1:


This is a dup of USB device access pop-up supression?. Basically the answer is to use an intent-filter on USB_DEVICE_ATTACHED and steer clear of the RequestPermission USB Host Mode API call.




回答2:


I answered this here, although I gather that duplicates across other SE sites are permitted.

In answer to why, it is as you surmised in said thread; because with your hardware you get different identifiers each time you connect, e.g. /dev/bus/usb/001/, /dev/bus/usb/002/ and so on.




回答3:


The Android just cannot remember my grant for my device But fortunately, I figured out the reason: I used hex values in the device_filter.xml. After I changed it to decimal values, everything just works fine. My Android can remember my permit then.



来源:https://stackoverflow.com/questions/15168148/usb-host-mode-device-access-permission-granted-but-not-remembered

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!