Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Reading content url on android QtQuick 5.15

    Mobile and Embedded
    4
    9
    754
    Loading More Posts
    • 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.
    • C
      cmorgan last edited by

      I am trying to read a file given to me by QFileDialog. This is the file returned
      0a9b092a-dd51-4468-8f61-135f8fe332ff-image.png

      I pass it to the c++ side but "filename" never returns anything

      55e77282-34d5-440c-8d19-48ccb6cecb7f-image.png

      Thanks in advance

      1 Reply Last reply Reply Quote 0
      • ekkescorner
        ekkescorner Qt Champions 2016 last edited by

        please take a look at these discussions:
        https://forum.qt.io/topic/113328/how-to-convert-android-content-url-and-use-it-to-open-file
        https://forum.qt.io/topic/113335/qfiledialog-getopenfilename-always-returns-empty-string-on-android

        ekke
        Qt Champion
        mobile business apps
        Qt Quick Controls 2 (Material style) for Android / iOS

        C 2 Replies Last reply Reply Quote 1
        • C
          cmorgan @ekkescorner last edited by

          @ekkescorner I've read them both, the first one doesn't mention anything about content url's (thatI see anyway) and the latter has the same suggestion from the moderator

          1 Reply Last reply Reply Quote 0
          • C
            cmorgan @ekkescorner last edited by

            @ekkescorner It seems to me the answer is "you don't"

            ekkescorner 1 Reply Last reply Reply Quote 0
            • ekkescorner
              ekkescorner Qt Champions 2016 @cmorgan last edited by

              @cmorgan I haven't tried native Android QFileDialog and Qt 5.15 yet - have to finish customer projects on 5.13.2 before
              But I have used a content url in my share example https://github.com/ekke/ekkesSHAREexample/blob/master/android/src/org/ekkescorner/utils/QSharePathResolver.java

              ekke
              Qt Champion
              mobile business apps
              Qt Quick Controls 2 (Material style) for Android / iOS

              1 Reply Last reply Reply Quote 2
              • M
                maitai_vw last edited by

                Hi,

                I am trying to use your nice QSharePathResolver class, but this time to resolve a directory name sent by QFileDialog::openExistingDirectory (native mode).

                This returns something in the form "content://com.android.externalstorage.documents/tree/home%3A" (just selected Documents directory on the phone).

                QSharePathResolver just throw an exception (catched) on that. How can I convert this to just a QDirectory?

                Running on qt 5.15.2, tested on Android 10 and 11

                Thanks for any clue,
                Philippe

                ekkescorner 1 Reply Last reply Reply Quote 0
                • ekkescorner
                  ekkescorner Qt Champions 2016 @maitai_vw last edited by

                  @maitai_vw is on my todo list ;-)
                  just too much work on customer projects (mobile apps Android, iOS)

                  ekke
                  Qt Champion
                  mobile business apps
                  Qt Quick Controls 2 (Material style) for Android / iOS

                  M 1 Reply Last reply Reply Quote 0
                  • M
                    Marek @ekkescorner last edited by

                    @ekkescorner HI
                    I'm trying to use your example to get filePath from android content:/..
                    I'm using QSharePathResolver but since I don't know Java at all ;) I have trouble calling this method, can you give me some hint ?
                    Here is Qt code:

                    QString PostManager::getFilePath(QUrl url) {
                    #ifdef Q_OS_ANDROID
                        QAndroidJniObject jsPath = QAndroidJniObject::fromString(url.toLocalFile());
                        QAndroidJniObject uri = QAndroidJniObject::callStaticObjectMethod("android/net/Uri","parse","(Ljava/lang/String;)Landroid/net/Uri;", jsPath.object());
                        QString filename =
                              QAndroidJniObject::callStaticObjectMethod(
                                  "org/ekkescorner/utils/QSharePathResolver", "getRealPathFromURI",
                                  "(Landroid/content/Context;Landroid/net/Uri)Ljava/lang/String;",
                                  QtAndroid::androidContext().object(),uri.object<jobject>()).toString();
                    

                    And here is debug from phone with the error:

                    W System.err: java.lang.NoSuchMethodError: no static method "Lorg/ekkescorner/utils/QSharePathResolver;.getRealPathFromURI(Landroid/content/Context;Landroid/net/Uri)Ljava/lang/String;"
                    W System.err: 	at org.qtproject.qt5.android.QtNative.startQtApplication(Native Method)
                    W System.err: 	at org.qtproject.qt5.android.QtNative$7.run(QtNative.java:620)
                    W System.err: 	at org.qtproject.qt5.android.QtThread$1.run(QtThread.java:61)
                    W System.err: 	at java.lang.Thread.run(Thread.java:923)
                    

                    Basically I need "file://..." to pass as videoSource for MediaPlayer, it can't read "content:/..."
                    Best Regards
                    Marek

                    1 Reply Last reply Reply Quote 0
                    • ekkescorner
                      ekkescorner Qt Champions 2016 last edited by

                      @Marek sorry - cannot help immediately. ... working on 5 new highly complex mobile business apps (some with Bluetooth SPP Printer, some with BLE Scanner, one with Beacons) last months
                      hopefully soon more time for community
                      now because of Apple requiring XCode 12 I finally have to update my tooling...
                      next week I'll move from Qt 5.13.2 to 5.15 and from macOS Mojave to Catalina, XCode from 11 to 12, Android NDK, SDK, ...
                      will take some days until all projects running again ;-)
                      Then I'll have to take a look at using native Android QFileDialog and probably rewrite my Pathresolver
                      will let you know ...

                      ekke
                      Qt Champion
                      mobile business apps
                      Qt Quick Controls 2 (Material style) for Android / iOS

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post