How to create a Java object in C++ using JNI?

1.2k views Asked by At

I want to initialize a SIP connection using native Android API and Qt Android Extras (JNI) and Qt. If I was programming in Java, I will create a SipProfile object to start a connection but in JNI (As I know) I just can execute methods in classes.

Can I create an object of type of a Java class? Am I have to do this?

Does QAndroidJniObject does this for me?

This class reference: http://developer.android.com/reference/android/net/sip/SipProfile.html

Sample code:

public SipProfile mSipProfile = null;
...

SipProfile.Builder builder = new SipProfile.Builder(username, domain);
builder.setPassword(password);
mSipProfile = builder.build();

Sample reference: http://developer.android.com/guide/topics/connectivity/sip.html

Update: I'm not using JNI itself. I'm using "Qt Android Extras".

1

There are 1 answers

0
Johann Oskarsson On

I used to know how to do this. Please forgive me if the answer is incorrect. I hope this gets you started.

You get a jni handle for the constructor you want to run. Then allocate/create a jobject and run the constructor on it.