linphone-developers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Linphone-developers] How to call JNI Method in Linphone library


From: Sylvain Berfini
Subject: Re: [Linphone-developers] How to call JNI Method in Linphone library
Date: Tue, 30 May 2017 15:09:27 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0

Hi,

If you are using linphone library, the following method will return the JNIEnv:

ms_get_jni_env();

For it to work properly, the simple way is to add the following in your native code:

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *ajvm, void *reserved)
{
    ms_set_jvm(ajvm);
}

Cheers,

Sylvain Berfini
Software Engineer @ Belledonne Communications
On 30/05/2017 14:55, Amine Ghabi wrote:
I have implemented a native method that call a java method, here everything is fine but now I need to call this native method in the Linphone C code but I do not know how to do it, here is the example that I did :

 JNIEXPORT jstring JNICALL
Java_namepackage_getCSR( JNIEnv* env, jobject obj){

    jstring jstr = (*env)->NewStringUTF(env, "CSR");
    jclass clazz = (*env)->FindClass(env, packageName2);
    jmethodID generateMthCSR = (*env)->GetMethodID(env, clazz, myMethodName, "(Ljava/lang/String;)Ljava/lang/String;");
    jobject result = (*env)->CallObjectMethod(env, obj, generateMthCSR, jstr);
    const char* str = (*env)->GetStringUTFChars(env,(jstring) result, NULL); // should be released
    printf("%s\n", str);
    return (*env)->NewStringUTF(env, str);
}
and now I need to call this native method in the linphone library code so when i try to like this :
char *csr = Java_namepackage_getCSR(?, ?); I don't know how to get instance of the JniEnv and the jobject . Thanks for your help  
Amine Ghabi Ingénieur iOS & Android  t. 06 03 81 87 91    a. 242 Rue de Bercy, 75012 Paris
Facebook  Google +  LinkedIn  Amin.ghabi1  Github 



_______________________________________________
Linphone-developers mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/linphone-developers


reply via email to

[Prev in Thread] Current Thread [Next in Thread]