1,關於java端類及接口定義請參考:html
android NDK 實用學習-獲取java端類及其類變量java
2,對傳過來的參數進行賦值:android
env->SetBooleanField(jobj, jfbdata, false); 數組
env->SetDoubleField(jobj, jfddata, 209.22); post
env->SetIntField(jobj, jfidata, 3653); 學習
env->SetByteField(jobj, jfcdata, 67); url
char data[10] = "4611354"; env->SetObjectField(jobj, jfsdata, env->NewStringUTF(data)); spa
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,獲取成員變量值:code
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,關於類中包含類的能夠依次類推,若有用到,之後後續完善!htm