我可以在清单中正确捕获经过过滤的USB附加通知:
<activity
android:name=".activities.MainActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<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>
但是,将其移动到目标接收器时,device_filter会被忽略,并且我会收到每个设备的通知:
<receiver
android:name="com.company.appname.receivers.UsbConnectionReceiver"
android:exported="true">
<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" />
</receiver>
谁能给我一个在第二种情况下将忽略过滤器的原因?这是上下文问题还是其他问题?
谢谢!