最近我一直在尝试根据我见过的所有样本和示例使用广播接收器接收 Intent android.hardware.usb.action.USB_DEVICE_ATTACHED。
我已经在 list 中声明了一个接收者;
<receiver android:name=".UsbDeviceReceiver">
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
<action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter"/>
我也在 Activity 代码中做了类似的事情 - onStart 和 OnStop 注册/注销接收器。
IntentFilter filter = new IntentFilter();
filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
registerReceiver(mUsbReceiver, filter);
但是,我发现 Intent 刚刚被捕获。观察 logcat,我可以看到附加 USB 设备会寻找要启动的 Activity ,而分离会广播分离 Intent 。根据上述样本,情况不应如此。
我是否遗漏了有关元数据的重要信息?我对 android.hardware.usb.action.USB_DEVICE_DETACHED 没有任何问题。也许这是安装在 galaxy s3 上的 android 版本的错误?也许这是 ICS 的“功能”。
欢迎提供相关信息!
最佳答案
这是一个已知缺陷:
http://code.google.com/p/android/issues/detail?id=25701
这里:
http://code.google.com/p/android/issues/detail?id=25703
但是不要屏住呼吸等待它被修复。当您查看错误报告时,给它加星标,这样您就会收到报告更新的通知。可能会有其他人的评论要求修复它。
关于android - USB_DEVICE_ATTACHED 只启动 Galaxy S3 ICS 的 Activity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11242730/