2014-10-20 145 views
2

我试图过滤显示USB连接对话框的某些设备,并根据我的理解,这可以通过创建设备过滤器,指定设备允许,然后处理我的意图活动。Android USB设备过滤器

我遇到的问题是无论连接什么设备(不限制在device_filter.xml中的列表),它都会提示。

如何限制连接提示到device_filter.xml中列出的设备?

device_filter.xml

<?xml version="1.0" encoding="utf-8"?> <resources> <usb-device vendor-id="1027" product-id="24597"> <usb-device vendor-id="1659" product-id="8963" > </resources>

该文件包含我希望白名单的设备。

 <activity 
     android:name=".Player" 
     android:clearTaskOnLaunch="true" 
     android:configChanges="orientation|keyboardHidden" 
     android:exported="true" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
     <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> 

我的活动内:

从AndroidManifest.xml中

​​

回答

3

有点晚,但你的过滤器不能很好地形成:

<usb-device vendor-id="1027" product-id="24597" /> 

你错了用斜线(/)关闭标签。