Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to handle filter-intent on android properly on Android
Forum Update on Monday, May 27th 2025

How to handle filter-intent on android properly on Android

Scheduled Pinned Locked Moved Solved Mobile and Embedded
5 Posts 3 Posters 2.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kuzulis
    Qt Champions 2020
    wrote on last edited by kuzulis
    #1

    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?

    ekkescornerE 1 Reply Last reply
    0
    • K kuzulis

      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?

      ekkescornerE Offline
      ekkescornerE Offline
      ekkescorner
      Qt Champions 2016
      wrote on last edited by
      #2

      @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/

      ekke ... Qt Champion 2016 | 2024 ... mobile business apps
      5.15 --> 6.8 https://t1p.de/ekkeChecklist
      QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

      1 Reply Last reply
      2
      • K Offline
        K Offline
        kuzulis
        Qt Champions 2020
        wrote on last edited by
        #3

        Many thanks, it was very useful link.

        Pablo J. RoginaP 1 Reply Last reply
        0
        • K kuzulis

          Many thanks, it was very useful link.

          Pablo J. RoginaP Offline
          Pablo J. RoginaP Offline
          Pablo J. Rogina
          wrote on last edited by
          #4

          @kuzulis if your issue is solved, please don't forget to mark your post as such! Thanks

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kuzulis
            Qt Champions 2020
            wrote on last edited by
            #5

            Yes, of course. But I'm just don't tried nothing yet. :)

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved