2

On Android platform in my native code I have allocated an int array

mBuffer = new int[BUFSIZE];

I want to send this to Java side, Java method is this

public void WriteBuffer(int[] buffer, int size) 
{

}

I call back to java code like this

const char* callback = "WriteBuffer";

mWriteMethod =  env->GetMethodID(cls, callback, "([II)V");     

This calls the java method its just that in my Java code the buffer is null. As I am really passing a pointer to memory that was dynamically allocated rather than an actual array is probably why it doesn't work but I don't know how to pass a pointer to Java. I need the buffer parameter as an integer array on the Java side anyway.

Anyone know how I can modify the above to get it to work?

Thanks

1
  • You don't need the 'size' parameter in that callback method. The Java code can use buffer.length. Commented Jun 12, 2012 at 1:14

1 Answer 1

2

My understanding of your question is you want call the java method WriteBuffer and pass a int[] to it.
Some pseudo-code which you will need in jni

jintArray buffer; 
buffer= (*env)->NewIntArray(env, BUFSIZE); 
(*env)->SetIntArrayRegion(env, buffer, 0,BUFSIZE, mBuffer);    

SetIntArrayRegion() will copy from mBuffer into the Java array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.