jni java传递byte数组,如何从Android的Java类的字节数组传递给JNIÇNDK?

I have byte array in java class , and i want to pass that byte array to JNI C class, I am not able to access that array in JNI C, Please Help!!!

解决方案

you need to declare the JNI function that receives the array like this (in Java):

private native void sendData(byte[] data);

you call the function like any other function:

sendData(buffer);

and then in your C code implement the function like this:

JNIEXPORT void JNICALL Java_com_packageXXX_yourClass_sendData( JNIEnv*

env, jobject thiz, jbyteArray data);

read the array:

byte * cData = env->GetByteArrayElements(data, &isCopy);

and release:

env->ReleaseByteArrayElements(data, cData, JNI_ABORT);

the above code is C++. To make it work for C you need to pass the jni environement (env) as the first parameter of the function you are calling, like this:

(*env)->GetByteArrayElements(env,...)

  • 0
    点赞
  • 0
    收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:深蓝海洋 设计师:CSDN官方博客 返回首页
评论
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值