对java传进来的数组进行操作并返回
public class MainActivity extends Activity {
public int[] j = {1,2,3,4,5,6,7,8,9};
static{
System.loadLibrary("hello");
}
public native int[] arrayTest(int[] ja);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast.makeText(this, ""+arrayTest(j)[0], 5000).show();
}
}
JNIEXPORT jintArray JNICALL Java_com_example_dsassdada_MainActivity_arrayTest
(JNIEnv *env, jobject obj, jintArray ja){
int length = (*env)->GetArrayLength(env,ja);//得到数组长度
int *arry = (*env)->GetIntArrayElements(env,ja,0);//得到指向java数组的指针
int i = 0;
for(i=0;i<length;i++){
*(arry+i) +=1;//每一项加一
}
(*env)->ReleaseIntArrayElements(env,ja,arry,0);//释放指向java数组的指针
return ja;
}