Forums

OverviewFelgo 2 Support (Qt 5) › how to select files from android native file dialog? (Qt and android question)

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #23540

    jrrobles79

    (I have already post this question on the Qt forum but still no answer, so I will try here)

    How other Felgo/Qt users have solved this issue? I haven’t able to find a solution for this, the most I have been able to get is the URI but I can’t find a way of how to transform it to a real path.

    I have read some android documentation following some posts like this https://stackoverflow.com/questions/15079406/qt-necessitas-reasonable-qfiledialog-replacement-skin?answertab=active#tab-top and https://stackoverflow.com/questions/3401579/get-filename-and-path-from-uri-from-mediastore/51227392#51227392 and looks like is a different method depending on the android versions and device.

    For example the code on the first post:

     QAndroidJniObject cursor = contentResolver.callObjectMethod("query", "(Landroid/net/Uri;[Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)Landroid/database/Cursor;", uri.object<jobject>(), 0, 0, 0, 0);
    QAndroidJniObject DATA = QAndroidJniObject::fromString("_data");
        jint columnIndex = cursor.callMethod<jint>("getColumnIndexOrThrow", "(Ljava/lang/String;)I", DATA.object<jstring>());
        cursor.callMethod<jboolean>("moveToFirst", "()Z");
    QAndroidJniObject result = cursor.callObjectMethod("getString", "(I)Ljava/lang/String;", columnIndex);
     return result.isValid() ? result.toString() : QString();

     

    crash my app on my device since it returns a null when is trying to query throught the cursor, according to some posts is because the parameter ‘_data’ dosen’t exist in some devices and versions.

    I have also find this java file: https://gist.github.com/tatocaster/32aad15f6e0c50311626

    but when I call the method to access this java class using:

    QAndroidJniObject::callStaticObjectMethod (...)

     

    is getting me an empty string  I even created a simple java test method and always return an empty string:

     

    // myfile.cpp
    QAndroidJniObject jniFullPath =  QAndroidJniObject::callStaticObjectMethod(
                                "com/iubo/app/utils/FilePath" // class name
                                , "getFilePath" // method name
                                , "(Ljava/lang/String)Ljava/lang/String;" // signature
                                , jniUri.object<jstring>() ); //Uri object
    qDebug() << "realpath: " << jniFullPath.toString(). // I expected "URI:"  + the uri but returns empty
    
    
    //Java method:
    public static String getFilePath(String uriPath){
    
        String realPath = "URI:" + uriPath;
       
        return realPath;
    }

     

    So in conclusion, looks that using JNI depends on android versions AND devices , and using the methods to communicate with java files aren’t working how https://doc.qt.io/qt-5/qandroidjniobject.html#details said it should work.

    how should I solve this?

     

     

     

     

     

Viewing 1 post (of 1 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support