Handling commandline args under Android



  • Hi!

    I was able to launch my Qt-Android app by associating file mimetype with it (using <intent-filters> in Manifest.xml) and tapping that file icon in device file browser.
    But the app can't see an argument (file path).
    Is it supported?



  • Seems it is not supported directly by Qt but I found the solution using JNI

    QString getRunArgument() {
      QString argument;
      QAndroidJniObject activity = QtAndroid::androidActivity();
      if (activity.isValid()) {
        QAndroidJniObject intent = activity.callObjectMethod("getIntent", "()Landroid/content/Intent;");
        if (intent.isValid()) {
           QAndroidJniObject data = intent.callObjectMethod("getData", "()Landroid/net/Uri;");
           if (data.isValid()) {
             QAndroidJniObject arg = data.callObjectMethod("getPath", "()Ljava/lang/String;");
             if (arg.isValid())
               argument = arg.toString();
           }
        }
      }
      return argument;
    }
    

    It works for me


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.