19

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?

4

3 回答 3

8

这是USB设备访问弹出抑制的dup?. 基本上答案是在 USB_DEVICE_ATTACHED 上使用意图过滤器并避开 RequestPermission USB 主机模式 API 调用。

于 2013-03-10T13:20:28.937 回答
3

我在这里回答了这个问题,尽管我认为其他 SE 站点之间的重复是允许的。

回答为什么,正如您在所述线程中所推测的那样;因为对于您的硬件,每次连接时都会获得不同的标识符,例如 /dev/bus/usb/001/、/dev/bus/usb/002/ 等等。

于 2013-03-11T08:52:33.377 回答
2

Android 只是不记得我对我的设备的授权但幸运的是,我找到了原因:我在 device_filter.xml 中使用了十六进制值。将其更改为十进制值后,一切正常。我的 Android 可以记住我的许可证。

于 2018-01-10T10:01:59.193 回答