hsu.tw
hsu.tw

Reputation: 148

Android UsbManager.openDevice(Device device) throw an Exception "device does not exist or be restricted"

I use a thread to send data to my usb-device (not data-storage) and get the return-data from device.

It worked fine in the first 5 minute. Data in, data out. (I almost start to sing in the sixth minute.)

Then suddenly it lost the connection.

There are the logcat message:

    java.lang.IllegalArgumentException: device /dev/bus/usb/001/002 does not exist or is restricted
    at android.os.Parcel.readException(Parcel.java:1331)
    at android.os.Parcel.readException(Parcel.java:1281)
    at android.hardware.usb.IUsbManager$Stub$Proxy.openDevice(IUsbManager.java:340)
    at android.hardware.usb.UsbManager.openDevice(UsbManager.java:255)

So, I check the code of UsbManager, trying to find out what is the IUsbManager...

Cool. An interface... and there is zero information about what it is. That is why I am here.

Has anyone with any clue???

Upvotes: 6

Views: 4472

Answers (1)

NSaran
NSaran

Reputation: 628

The app should be listening to the UsbManager.ACTION_USB_DEVICE_ATTACHED and UsbManager.ACTION_USB_DEVICE_DETACHED Intents. It should attempt to open the device received from the attached intent.

The error usually happens when the app tries to re-open the connection to a UsbDevice. When the UsbDevice reconnects it is assigned a new hardware address (Old: /dev/bus/usb/001/002, New: /dev/bus/usb/001/003).

Upvotes: 2

Related Questions