Android USB Device Permission and Intent Filter

强颜欢笑 提交于 2019-11-30 14:33:51
Samuel Reque Zambrana

I have the same problem, in your AndroidManifest.xml in the Activity that use the Device write this:

<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" />

You also have to create a filter file in your xml resources, eg res/xml/device_filter:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    <usb-device vendor-id="26214" product-id="26214" />
    </resources>

The vendor-id and product-id here have to be given in decimal - above both the VID and PID are 0x0123. you see USB device access pop-up supression?

you must not call mManager.requestPermission(device, mPermissionIntent), so you have to directly call mManager.openDevice(mDevice); and you can communicate normally without the need appear permission pop-up message.

Regards, Samuel Reque samo_reque@hotmail.com

I don't undersand your question well but I think solution is like this..

<activity ...>
<intent-filter >
            <action android:name="android.intent.action.MAIN" />                
            <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
            <action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
            <meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" android:resource="@xml/device_filter"/>
            <category android:name="android.intent.category.HOME" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!