我想在插入 android 设备时检测 MTP/PTP 设备。我知道有一种方法使用 Intent:android.hardware.usb.action.USB_DEVICE_ATTACHED
然后定义使用资源的元数据<usb-device class="6" subclass="1" protocol="1">
,但它不起作用。系统不会将此意图发送到已注册的应用程序。
因此,有人知道该怎么做吗?
could you please specify what is the device you are using for testing? It is very likely that your device has no PTP/MTP specific values in class, subclass and protocol for the USB device descriptor and/or interface descriptor. See this: http://events.linuxfoundation.org/sites/events/files/slides/Media%20Transfer%20Protocol.pdf Some devices advertise themselves as Mass Storage devices or Vendor Specific. If that is the case the only way is to try matching the vendor id and product id of the devices you would like to support. Here is also a list of MTP devices with their vendor id and product id: http://sourceforge.net/p/libmtp/code/ci/HEAD/tree/src/music-players.h.
Hope this helps.
您是否通过添加将机器设置为 USB 主机进入 AndroidManifest.xml:
<uses-feature android:name="android.hardware.usb.host" />