Important: Please read the Qt Code of Conduct -

Unable to get java class from jni enviroment using android extras

  • Hi,
    I wanted to create the object of a class as created in the class:

    QAndroidJniObject javaNotification = QAndroidJniObject::fromString(m_notification);

    QAndroidJniEnvironment jnienvironment;

    jclass myclass= jnienvironment->FindClass("org/qtproject/example/notification/NotificationClient");

    qDebug()<<"jni class object is >>"<<myclass; //unable to get the class of java here

    QAndroidJniObject nitificationObj(myclass);

    qDebug()<<"jni object is :"<<nitificationObj.toString();

    nitificationObj.callMethod<void>("notify", "(Ljava/lang/String;)V", javaNotification.object<jstring>());

    If use static method call then it is working. but, when i try to access the java class, it is not working. kindly provide the solution for this problem.

    Thanks and regards
    Krnathi Talluri

  • For using a java class into a Qt project with android extras, I simple do this:
    // create the java object calling the constructor without any arguments
    QAndroidJniObject androidInterface("com/myproject/AndroidInterface");
    // then call a method specifying correctly all arguments
    jboolean result = androidInterface.callMethod<jboolean>("saveWhatever", "(Landroid/app/Activity;I)Z", activity, whatever);

    And it works perfectly.

Log in to reply