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

Jérôme Godbout godboutj at amotus.ca
Thu Jun 28 21:56:47 CEST 2018


Hi, first I'm not a specialist in any case, just giving some tips, that might help seek. I think you need the following:

  1.  declare intent into the manifest
  2.  make the java intent handler with a native function callback when this occur.
     *   You probably need to filter the event and reply immediately
  3.  from the native callback send message queue into the Qt thread with given arguments
  4.  Register and init the java intent when application init.

That would be my workflow to try to do it with Qt. Maybe some expert could jump in on how to do each step or if any better alternative exist.


I would be interest into how to achieve this too, if you can keep the reply public that would be nice.

Thanks,

Jerome


________________________________
From: Interest <interest-bounces+godboutj=amotus.ca at qt-project.org> on behalf of Dirk Hohndel <dirk at hohndel.org>
Sent: June 28, 2018 1:32 PM
To: android-development at qt-project.org; interest at qt-project.org
Subject: [Interest] responding to an Android intent in a Qt app

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

_______________________________________________
Interest mailing list
Interest at qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180628/b192feb0/attachment.html>


More information about the Interest mailing list