Learning Android JNI, a two-dimensional integer array of the transfer took me a long time, in the online search of information are not complete, of course, the final success, written here is to remember, of course, someone search and use I will be very happy.
In Android Java filEPublic
Native BooleanAdd
int[] Qizidata,.....) Use the JDK tool to produce JNI *.h files your project path>. Javajdk1.6.0_10binjavah-classpath./binJAVA Class name
//**************************************************************************//Two-D array Java-"JniJniexport jint jnicall java_com_jung_add (jnienv * env, jobjectobj, Jobjectarray qizidata,jint value1, jintvalue2) {j Inti,j; JINTQIZI[1024][1024];//fixed array, for testingJarraymyarray; Intsize = (*env)->getarraylength (env, qizidata); for (i= 0; i < size &&i<1024; i++) {myarray = ((*env)->getobjectarrayelement (env, qizidata,i)); int col = (*env)->getarraylength (Env,myarray); Jint *coldata = (*env)->getintarrayelements (env, (Jintarray) myarray,0); for (j=0; j<col&& j <1024;j++) {qizi[i][j]= coldata[j]; } (*ENV)->releaseintarrayelements (env, (Jintarray) myarray, coldata,0); } return (Qizi[0][0]+qizi[9][0]);}
//**************************************************************************//Two-D array jni-"JavaJniexport Jobjectarray Jnicalljava_com_marakana_nativelib_getintarray
(jnienv *env, Jobject obj, jintx, jint y)
{Jobjectarray ret; int i = 0; int j = 0; Jclassintarrcls = (*env)->findclass (env, "[I"); if (null== intarrcls) return NULL; ret = (*env)->newobjectarray (env, x * y, intarrcls,null); JINTTMP[1024];//fixed array, test, attention do not overflowfor (i= 0; i < x; i++) {Jintarray intarr = (*env)->newintarray (env,y); for (j = 0; J <y; J + +) {Tmp[j] = i + j; } (*env)->setintarrayregion (Env,intarr, 0, y,tmp); (*env)->setobjectarrayelement (Env,ret, I,intarr); (*env)->deletelocalref (Env,intarr); } Returnret;}//**************************************************************************//The following code is online search, no verification, forget the source, please the original author forgive Me//Two-D string array JNI extraction C_languge syntaxJniexport void Jnicall java_testarray_printarrays (jnienv *env, Jclass class, Jobjectarray array) { Intsize = (*env)->getarraylength (env, array); for (int i = 0; i < size; i++) &NBSP;{&NB sp; jarray myarray = ((*env)->getobjectarrayelement (env, array,i)); int leng = (*env)->getarraylength (env, myarray); printf ("Length:%dn", Leng); for (int j = 0; j< Leng; j + +) { jstring string = ((*env)->getobjectarrayelement (env, myarray,i)); const char * chars = (*env)->getstringutfchars (env, string, 0); & nbsp printf ("%s n", chars); (*env)->releasestringutfchars (env , string, chars); } }}
Android JNI Two-dimensional array delivery