[Interest] responding to an Android intent in a Qt app

Dirk Hohndel dirk at hohndel.org
Thu Jun 28 19:32:44 CEST 2018


Hi,

I'm pretty sure that I'm missing something fairly basic...

Our Android Qt app registers its desire to be opened when a certain type of
USB device is plugged into the Android phone / tablet:

AndroidManifest.xml:
...
            <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" />
...

The xml/device_filter.xml file is setup to list the devices that we want
to respond to.

Now if the user plugs in such a device, an Android system message pops up
and asks if they want to launch our app. Awesome, exactly what I want.

Here comes the question - inside the app, how do I know that I was
launched by that intent? And how do I get to the extra data that is
available through that intent?

Andrid docs tell me
(https://developer.android.com/guide/topics/connectivity/usb/host) that in
Java all I need to do is:

UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);

and now I can get the deviceName, PID and VID for that device...

But how do I do this from a Qt app?

I found the documentation here http://doc.qt.io/qt-5/qandroidintent.html
but that still doesn't tell me how I know that I have received an intent
and how to get the Java intent object.

Because once I know that I think I should be able to get to that info via
QAndroidIntent::extraVariant(const QString &key) ...

Does someone have a working example of how a Qt Android app can respond to
a USB device being plugged in? Or any other pointers to working code?

Thanks

/D




More information about the Interest mailing list