【问题标题】:How to get application arguments on Qt for android如何在 Qt for android 上获取应用程序参数
【发布时间】:2015-01-04 23:01:25
【问题描述】:

我有一个 Qt 应用程序,它在 AndroidManifest.xml 中定义了文件关联,所以当我在浏览器中选择一个文件时,我会得到一个关联应用程序的列表。我的应用程序在列表中,但是当我选择它时,文件路径未在我的main() 方法中的argv 列表中传递。路径是如何传递给应用程序的,我如何在 Qt/C++ 中拥有它?

【问题讨论】:

    标签: java android c++ qt qtandroidextras


    【解决方案1】:

    经过一番研究,我得出了以下可行的解决方案:

    void loadAndroidFile()
    {
    #ifdef Q_OS_ANDROID
        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 path = data.callObjectMethod("getPath", "()Ljava/lang/String;");
                    if (path.isValid())
                        // Here path.toString() returns the path of the input file
                        QMetaObject::invokeMethod(rootComponent, "setSourcePath", Q_ARG(QVariant, QVariant("file://" + path.toString())));
                }
            }
        }
    #endif
    }
    

    【讨论】:

      猜你喜欢
      • 2011-02-24
      • 1970-01-01
      • 2014-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多