开发者

Bluetooth transfer from PC to Android through RFCOMM

I am trying to stream data from a laptop to native code in an android phone. Am able to pair with laptop and get data for sometime, but the native code crashes with the following message later:

"failed adding to JNI pinned array ref table".

Code snippet:

// Java code for Bluetooth read handler

case MESSAGE_READ:

byte[] readBuf = (byte[]) msg.obj;

// Send the data in the buffer to native code sendData(readBuf, msg.arg1);

........................................................................

// C-code:

...sendData (JNIEnv *env, jclass cl, jbyteArray arr, jint size)

{

.....

jbyte buffer = (jbyte)env->GetByteArrayElements(arr, &isCopy);

....// copy the buffer to a local variable.

if (isCopy == JNI_TRUE) {

env->ReleaseByteArrayElements(arr, buffer, JNI_ABORT);

}

What could be wrong? I am already using similar code for array t开发者_如何学Goransfer between Java and C elsewhere in the code, and that works fine.


This issue got resolved. Actually, the "other" portion which i am referring to had the problem.

Instead of GetByteArrayElements(), used GetByteArrayRegion() so that there is no pinning problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜