Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8855785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:12:53+00:00 2026-06-14T14:12:53+00:00

I have a requirement for creating call backs between native code ( c language

  • 0

I have a requirement for creating call backs between native code ( c language code) and Android code .
I wrote JNI functions for calling C code from the android like this

JNI code here

#include <android/log.h>

void initSocket(); 

#ifdef __cplusplus
extern "C" {
#endif

  JNIEXPORT void JNICALL Java_org_pjsip_pjsua_pjsua_1appJNI_initSocket(JNIEnv *jenv, jclass jcls) {

    __android_log_write(ANDROID_LOG_INFO, " JNI CODE ", " APP INIT SOCKET");        
    initSocket();        
  }
}

C code looks like this

void initSocket()
{
    /// some more stuff
    printf("  initSocket function ");           
}

static int worker_thread(void *unused)
{       
    /// some more stuff
    return 0;
}

pj_bool_t on_rx_data1(pj_stun_sock *stun_sock, void *pkt, unsigned pkt_len, const pj_sockaddr_t *src_addr, unsigned addr_len)
{      
    /// some more stuff    
    return PJ_TRUE;
}

pj_bool_t on_data_sent1 (pj_stun_sock *stun_sock, pj_ioqueue_op_key_t *send_key, pj_ssize_t sent)
{        
    /// some more stuff
    return PJ_TRUE;  
}
pj_bool_t on_status1(pj_stun_sock *stun_sock, pj_stun_sock_op op, pj_status_t status)
{        
    /// some more stuff
    returnsockaddress();            
    return PJ_TRUE;
}

char* returnsockaddress()
{     
    /// some more stuff   
    return ipinttostring(sock_address);
}

char* ipinttostring(unsigned int addr )
{       
    /// some more stuff
    return fullIP;
}

this is the code i am using in C language, calling initSocket() function from JNI. Now i want to create a callback from this C code when on_status1 function called in this code. this on_status1 will repeat in few seconds when ever it’s called i want to call a function in android code.

EDIT

I tried like this, but not succeeded

JNIEXPORT void JNICALL Java_org_pjsip_pjsua_pjsua_1appJNI_initSocket(JNIEnv *jenv, jobject obj) {

      __android_log_write(ANDROID_LOG_INFO, " JNI CODE ", " APP INIT SOCKET");            
      initSocket();             
      jclass cls = jenv->GetObjectClass(obj);
      jmethodID methodid = env->GetMethodID(cls, "callback", "()V");            
      if(!methodid) {
          return;
      }            
      jenv->CallVoidMethod(obj , methodid);            
  }

I was declared function like this in android code.

public static void callback(String value) {
    Log.e(TAG, "value:" + value);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:12:54+00:00Added an answer on June 14, 2026 at 2:12 pm

    Try this :

    JNIEXPORT void JNICALL Java_org_pjsip_pjsua_pjsua_1appJNI_initSocket(JNIEnv *jenv, jobject obj) {
      __android_log_write(ANDROID_LOG_INFO, " JNI CODE ", " APP INIT SOCKET");            
      initSocket();             
      // jclass cls = (*jenv)->GetObjectClass(jenv, obj);
      // or something like this :
      jclass cls = (*jenv)->FindClass(jenv, "org/pjsip/pjsua/pjsua_appJNI"); 
      jmethodID methodid = (*jenv)->GetStaticMethodID(jenv, cls, "callback", "(Ljava/lang/String;)V");            
      if(!methodid) {
          return;
      }       
      jstring jstr = (*jenv)->NewStringUTF(jenv, "Hello from C"); 
      (*jenv)->CallStaticVoidMethod(jenv, cls, methodid, jstr); 
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we have a requirement of dynamically creating a XML document from the USer entered
In our project we have requirement that, after receiving sms message from third party
I have X number of RadioButtons (Silverlight). Normally this value is between 2-5. Call
I have requirement of creating/splitting my div elements horizontally and vertically on click of
I'm creating a WiX installer for an application. I have a requirement to make
I have a requirement in which i need to call webservice 12 times for
I have the following requirement for creating a user profile in my application: User
I'm creating an MSI package and I have the requirement to set the text
I have a requirement to use business objects to call strongly typed table adapters
I am creating a 3-column UI with grid splitters between the columns. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.