0

I´m working on some application which uses Media Transfer Protocol to read Photos from a Camera connected to my Android Tablets USB host (Android 3.1, Acer Iconia Tab A500).

I found some tutorials describing how to work with USB and I got copying from USB camera to SD-Card already working.

There is only one problem I have: All the tutorials wait for USB_DEVICE_ATTACHED-Intent and then open a UsbDeviceConnection for communicating with the device that is sent within the intents Bundle.

So I would like to be able to manually start an activity which accesses USB - WITHOUT receiving this intent. The Problem now is, that I cannot open an USBConnection like this

UsbDeviceConnection usbDeviceConnection = usbManager.openDevice(usbDevice);

It simply returns null. If I re-plugin the device and select my Activity as Intent receiver, it works fine. I think this must be because of the IntentReceiver having some exclusive permissions on the USB device.

My Manifest looks like this:

    <activity
        android:name=".ImageActivity"
        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>

So one example: What if a user has set Galery as default for USB devices. How can I access the USB device in this case?

1 Answer 1

2

I have found the USB Host mode API guide documentation to be highly useful in this area.

http://developer.android.com/guide/topics/connectivity/usb/host.html#discovering-d

The most important note is that if you have NOT received a UsbDevice from an activity, then you will need to request permission to communicate with it. This process is described in the link provided.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.