Paste #zHwuO8ypR

void AccountKitReceiver::handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject &data)
{
    qDebug() << receiverRequestCode << resultCode << data.isValid();
    
    const QString resultKey = QAndroidJniObject::getStaticObjectField<jstring>("com/facebook/accountkit/AccountKitLoginResult",
                                                                               "RESULT_KEY").toString();
    QAndroidJniObject loginResult = data.callObjectMethod("getParcelableExtra",
                                                          "(Ljava/lang/String;)Landroid/os/Parcelable;",
                                                          QAndroidJniObject::fromString(resultKey).object());

    const QAndroidJniObject error = loginResult.callObjectMethod("getError", "()Lcom/facebook/accountkit/AccountKitError;").object();
    if (error.isValid()) {
        qDebug() << "AccountKit error";
    } else if (loginResult.callMethod<jboolean>("wasCancelled")) {
        qDebug() << "Cancelled";
    } else {
        const QAndroidJniObject token = loginResult.callObjectMethod("getAccessToken", "()Lcom/facebook/accountkit/AccessToken;").object();
        qDebug() << "getAccessToken" << token.isValid();
        if (token.isValid()) {
            const QAndroidJniObject id = token.callObjectMethod<jstring>("getAccountId");
            qDebug() << "got token" << id.toString();
        } else {
            const QAndroidJniObject code = loginResult.callObjectMethod<jstring>("getAuthorizationCode");
            qDebug() << "got code" << code.toString();
        }
    }
}