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: Amine Ghabi
Subject: Re: [Linphone-developers] How to call JNI Method in Linphone library
Date: Tue, 30 May 2017 15:40:13 +0200

Thanks for your reply, but that's not the problem because when I try to call my native method in your "account_creator.c" code, I have this error there :
 ==> too few arguments to function call, expected 2, have 0
 Char * csr = Java_namepackage_getCSR (); 
so I don't know how to call my native method from your code and how to pass arguments, because in Java code it's simple juste I call it like this : getCSR() without arguments.
Thanks very much 

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 


2017-05-30 15:09 GMT+02:00 Sylvain Berfini <address@hidden>:

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


_______________________________________________
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]