I need help with one issue. I have 2 (or more) activities that manage the USB_DEVICE_ATTACHED filter, and in each of them I have assigned different meta-data files. IE:
<activity
android:name="com.app.ui.ActivityOne"
android:launchMode="singleTop"
android:directBootAware="true"
android:exported="false"
android:theme="@android:style/Theme.NoDisplay">
<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/usb_device_filter_one" />
</activity>
<activity
android:name="com.app.ui.ActivityTwo"
android:launchMode="singleTop"
android:directBootAware="true"
android:exported="false"
android:theme="@android:style/Theme.NoDisplay">
<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/usb_device_filter_two" />
</activity>
And these are the meta-data files:
res/xml/usb_device_filter_one.xml
<resources>
<usb-device vendor-id="12216"/>
</resources>
res/xml/usb_device_filter_one.xml
<resources>
<usb-device vendor-id="4567"/>
</resources>
If I connect the device specified in the XML file for "ActivityOne" the system ask me for USB permissions and the activity is launched automatically after give permissions. But if I connect the device specified in the XML of "ActivityTwo", the systems show me a Chooser with my own app two times, and sometimes behind (in background) the permissions dialog.
I though that specifying a meta-data file for the intent-filter the system only will launch that activity and not... Seems to be an order on something similar with the intent filters. I try to merge the usb_device_filter.xml files dinamically or setting android:prority, but without satisfactory result.
I need do this, because my app must manage different types of USB devices, such printers, scanners, RFID, dataphones, etc and of different manufacturers and some of the are connected using the manufacturer SDK and other using the standard USB Connection. And theses activities and filters are specified in different AAR libraries to manage each type of device.
Anyone have an idea to solve this?
My last attempt is to create an unique usb_filter.xml file with all the vendor-ids and product-ids and determine in a unique Activity the type of USB device and act accordingly. But if I do theses and I implement a new device in any of the AARs libraries I must remember to update this unique usb_filter.xml file