Planned maintenance has been done but it did not solve the problem. So work will continue on this and a new time for trying updates will be announced asap.

How to call JAVA method that returns a String?



  • I would like to call a JAVA method that is in my QtActivity that return a string.

    I've tried these, but all gives me a compilation error:

    jstring value = QtAndroid::androidActivity().callMethod<jstring>("getUser", "()Ljava/lang/String;");
    
    jstring value = QtAndroid::androidActivity().callMethod<jstring>("getUser");
    
    error: undefined reference to '_jstring* QAndroidJniObject::callMethod<_jstring*>(char const*, char const*, ...) const'
    


  • I found it!

        QAndroidJniObject juser = QtAndroid::androidActivity().callObjectMethod("getUser", "()Ljava/lang/String;");
        QString user = juser.toString();
    


  • Thanks for the tip. The problem was callMethod vs callObjectMethod. I think callObjectMethod is for functions that return L types (classes) and the former for primitive types.

    Thanks


Log in to reply