chip
chip

Reputation: 1789

How to make int value in android usb host vendor-id value

I'm using USB host API for my android app. My code follows what is required in the developer site. Now I got issue on the device_filter.xml, android doesn't recognize the vendor-id="03eb" as int

It gives me this warning:

W/UsbSettingsManager( 1455): java.lang.NumberFormatException: Invalid int: "03eb"
W/UsbSettingsManager( 1455): at java.lang.Integer.invalidInt(Integer.java:138)
W/UsbSettingsManager( 1455): at java.lang.Integer.parse(Integer.java:375)

This is true, but how do I make this into an int in <usb-device vendor-id="03eb"?

enter image description here

AndroidManifest.xml file:

<activity
    android:name="com.example.usb.MainActivity"
    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>

In the device_filter.xml

<resources>
    <usb-device vendor-id="03eb" product-id="6201" />
</resources>

Upvotes: 3

Views: 3008

Answers (2)

sanmai
sanmai

Reputation: 30911

You can pass hexadecimal numbers in an appropriate notation:

<resources>
    <usb-device vendor-id="0x03eb" product-id="0x6201" />
</resources>

Upvotes: 0

Mike Ortiz
Mike Ortiz

Reputation: 4041

Vendor and Product ids must be integers, but you are passing hexadecimal values. You can simply convert hex to an integer representation. See this link. Here are the conversions:

03eb -> 1003

6201 -> 25089

Upvotes: 3

Related Questions