标签:
1,关于java端类及接口定义请参考:
android NDK 实用学习-获取java端类及其类变量
2,对传过来的参数进行赋值:
env->SetBooleanField(jobj, jfbdata, false);
env->SetDoubleField(jobj, jfddata, 209.22);
env->SetIntField(jobj, jfidata, 3653);
env->SetByteField(jobj, jfcdata, 67);
char data[10] = "4611354"; env->SetObjectField(jobj, jfsdata, env->NewStringUTF(data));
1 // 获取Java中Int数组赋值 2 jintArray jint_arr = (jintArray)env->GetObjectField(jobj, jiarr); 3 int arrInt[10] = {0}; 4 for(int i = 0; i < 10; ++i){ 5 arrInt[i] = 220+i; 6 } 7 env->SetIntArrayRegion(jint_arr, 0, 10, arrInt); 8 9 // 获取Java中byte数组赋值 10 jfieldID jbyteArr = env->GetFieldID(jcSetDataMgr, "byteArr", "[B"); 11 char arrByte[10] = "20200825"; 12 jbyteArray jbyte_arr = (jbyteArray)env->GetObjectField(jobj, jbyteArr); 13 env->SetByteArrayRegion(jbyte_arr, 0, 8, (const signed char*)arrByte);
3,获取成员变量值:
bool bData = env->GetBooleanField(jcSetDataMgr, jfbdata);
double dData = env->GetDoubleField(jcSetDataMgr, jfddata);
int iData = env->GetIntField(jcSetDataMgr, jfidata);
char cData = env->GetByteField(jcSetDataMgr, jfcdata);
1 jfieldID jfsdata = env->GetFieldID(jcSetDataMgr, "sData", "Ljava/lang/String;"); 2 jstring jtestStr = (jstring)(env->GetObjectField(jcSetDataMgr, jfsdata)); 3 const char* testStr = env->GetStringUTFChars(jtestStr, NULL); 4 char testData[100] = {0}; 5 strcpy(testData, testStr); 6 env->ReleaseStringUTFChars(jtestStr, testStr);
1 jfieldID jiarr = env->GetFieldID(jcSetDataMgr, "intArr", "[I"); 2 if(NULL == jiarr){ 3 DEBUG_OUT("jfbdata fail!"); 4 } 5 6 // 获取Java中数组属性arrays的对象 7 jintArray jint_arr = (jintArray)env->GetObjectField(jobj, jiarr); 8 9 int arrInt[10] = {0}; 10 for(int i = 0; i < 10; ++i){ 11 arrInt[i] = 220+i; 12 } 13 env->GetIntArrayRegion(jint_arr, 0, 10, arrInt);
4,关于类中包含类的可以依次类推,如有用到,以后后续完善!
android NDK 实用学习-java端对象成员赋值和获取对象成员值
标签:
原文地址:http://www.cnblogs.com/dhf-0214/p/4612740.html