android - A correct way to convert byte[] in java to unsigned char* in C++, and vice versa? -
i'm newbie in c++ , jni, try find correct way convert byte[] in java unsigned char* in c++ using jni, , vice versa ! (i'm working on android) after looking solution in google , so, haven't found details way convert byte[] in java c++. please me, , provide solution vice versa (unsigned char* in c++ byte[] in java). much
- byte[] in java unsigned char* in c++:
java :
private static native void nativereceivedatafromserver(byte[] value, int length);
jni:
... (jnienv* env, jobject thiz, jbytearray array, jint array_length) { ??? }
ps: modified question being real question problem :(
you can use convert unsigned char
array jbytearray
jbytearray as_byte_array(unsigned char* buf, int len) { jbytearray array = env->newbytearray (len); env->setbytearrayregion (array, 0, len, reinterpret_cast<jbyte*>(buf)); return array; }
to convert other way around...
unsigned char* as_unsigned_char_array(jbytearray array) { int len = env->getarraylength (array); unsigned char* buf = new unsigned char[len]; env->getbytearrayregion (array, 0, len, reinterpret_cast<jbyte*>(buf)); return buf; }
Comments
Post a Comment