Nominate our 2022 Qt Champions!

Query google username on Qt under Android

  • I'm trying to get the google username in my android application, i'm using JNI to execute the java classes but i'm stuck with the Acccounts array.

    int main(int argc, char *argv[])
        QApplication app(argc, argv);
        QAndroidJniObject activity = QtAndroid::androidActivity();
        QAndroidJniObject accountManager =       QAndroidJniObject::callStaticObjectMethod("android/accounts/AccountManager","get","(Landroid/content/Context;)Landroid/accounts/AccountManager;",activity.object());
    if(accountManager.isValid()) // until here is working
        // i would like to convert the next line in JNI code to obtain the google username. 
        // java code
        Account[] accounts = manager.getAccountsByType("");
        qDebug() << "OK";
        qDebug() << "NOK";

  • It would be much easier for you to have a Java method return that name as string to you. Add a helper class to your project with a static method to do all the "dirty work" and return just what you want. This way you just have to worry about getting the result with JNI, and not processing it.

Log in to reply