How to handle filter-intent on android properly on Android
-
Hi,
I have registered my custom URI scheme to launch my application:
<intent-filter> <action android:name=\"android.intent.action.VIEW\" /> <category android:name=\"android.intent.category.DEFAULT\" /> <category android:name=\"android.intent.category.BROWSABLE\" /> <data android:scheme=\"https\" android:host=\"foo.bar.com\" /> </intent-filter>
So, when the user clicked on following URL: https://foo.bar.com/baz then my application starts sucessfully. And I need to "intercept" this URL in my Qt application.
In my activity I have re-implemented this methods:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent(); Log.d(TAG, "On create intent: " + intent); String uri = intent.getDataString(); handleUrl(uri); } @Override protected void onNewIntent(Intent intent) { Log.d(TAG, "On new intent: " + intent); String uri = intent.getDataString(); handleUrl(uri); } public static native void handleUrl(String url); // <<< This is static JNI method (it emits the Qt signal)
A problem occurs when my application was not started in a moment when the user clicked on that URL. In this case gets called the JAVA's onCreate() method (instead of onNewIntent() method). And this does before than QApplication instance will be created. So, I can't emit any signals.
I tried to store the received URL's to the Q_GLOBAL_STATIC variable when the handleUrl() gets called, and to read this Q_GLOBAL_STATIC variable after the QApplication gets constructed. But problem is that that Q_GLOBAL_STATIC variable has different instances (pointers) in both cases, and inside QCoreApplication that variable is empty.
Does anybody faced with 'intent-filters' on Android && Qt?
-
Hi,
I have registered my custom URI scheme to launch my application:
<intent-filter> <action android:name=\"android.intent.action.VIEW\" /> <category android:name=\"android.intent.category.DEFAULT\" /> <category android:name=\"android.intent.category.BROWSABLE\" /> <data android:scheme=\"https\" android:host=\"foo.bar.com\" /> </intent-filter>
So, when the user clicked on following URL: https://foo.bar.com/baz then my application starts sucessfully. And I need to "intercept" this URL in my Qt application.
In my activity I have re-implemented this methods:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent(); Log.d(TAG, "On create intent: " + intent); String uri = intent.getDataString(); handleUrl(uri); } @Override protected void onNewIntent(Intent intent) { Log.d(TAG, "On new intent: " + intent); String uri = intent.getDataString(); handleUrl(uri); } public static native void handleUrl(String url); // <<< This is static JNI method (it emits the Qt signal)
A problem occurs when my application was not started in a moment when the user clicked on that URL. In this case gets called the JAVA's onCreate() method (instead of onNewIntent() method). And this does before than QApplication instance will be created. So, I can't emit any signals.
I tried to store the received URL's to the Q_GLOBAL_STATIC variable when the handleUrl() gets called, and to read this Q_GLOBAL_STATIC variable after the QApplication gets constructed. But problem is that that Q_GLOBAL_STATIC variable has different instances (pointers) in both cases, and inside QCoreApplication that variable is empty.
Does anybody faced with 'intent-filters' on Android && Qt?
@kuzulis please take a look at https://github.com/ekke/ekkesSHAREexample and the corresponding blog https://blog.qt.io/blog/2018/01/16/sharing-files-android-ios-qt-app-part-2/
-
Many thanks, it was very useful link.
-
@kuzulis if your issue is solved, please don't forget to mark your post as such! Thanks
-
Yes, of course. But I'm just don't tried nothing yet. :)