• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

call jni method from another method

 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i want to know if we can call a jni method in another method, because it never worked for us.

so let me explain in detail.


i have a method (function)called in c++ file named, let us say phone.cpp

void answer()

we have written a jni for that method and modified the void answer to

JNIEXPORT void JNICALL Java_testall_answer(JNIEnv *env, jobject jobj)

now we wanted to call the void answer() method in another function of the c++ file (phone.cpp).

how can it be made.

we tried

answer();
Java_testall_answer();
Java_testall_answer(JNIEnv *env, jobject jobj);
JNICALL Java_testall_answer(JNIEnv *env, jobject jobj);
JNICALL Java_testall_answer();

nothing worked..

kindly help.


thanks in advance
 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bharani rao wrote:Java_testall_answer(JNIEnv *env, jobject jobj);

What happens if you remove the types:
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hi rob,

it did not work..

i doubt if it is possible..

thank you in advance.
 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show me the method that is trying to call the native method?
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi rob,

this is the api that is calling that jni method

static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id,pjsip_rx_data *rdata)


this is from pjsip stack



thank you
 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then it seems that you have no access to JNIEnv* and jobject variables to pass to that method. You need to have a reference to those somehow.
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you rob....

i will try and inform you the status.
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi rob,

we tried hard and managed to proceed with our project without calling the jni method n another method..
we recreated the things done in the other method in the jni method and an additional method



thank you.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bharani rao wrote:hi rob,

we tried hard and managed to proceed with our project without calling the jni method n another method..
we recreated the things done in the other method in the jni method and an additional method


It strikes me that this is the better implementation anyway. Write a non-JNI version of your code, then implement the JNI method to call the non-JNI one to get the work done. That way there's no code duplication, and the non-JNI method can be easily called from wherever.
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ernest,

you are right...
it worked for us... it is easy if we do so with out any complications like the other procedure



thank you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic