{"id":3506,"date":"2022-07-21T14:00:44","date_gmt":"2022-07-21T06:00:44","guid":{"rendered":"https:\/\/learn-house.idv.tw\/?p=3506"},"modified":"2022-07-27T22:30:24","modified_gmt":"2022-07-27T14:30:24","slug":"androidjni%e5%91%bc%e5%8f%abcc%e5%87%bd%e5%bc%8f%e5%82%b3%e9%81%9eint-array%e5%8f%83%e6%95%b8%e8%88%87%e8%bf%94%e5%9b%9earray%e5%80%bc","status":"publish","type":"post","link":"https:\/\/learn-house.idv.tw\/?p=3506","title":{"rendered":"[Android]JNI\u547c\u53ebC\/C++\u51fd\u5f0f\u50b3\u905eInt Array\u53c3\u6578\u8207\u8fd4\u56deArray\u503c"},"content":{"rendered":"<p>\u4e0a\u5c64Java\u547c\u53ebC\/C++\u7684\u51fd\u5f0f<br \/>\n[java]<br \/>\npublic native void 2DArrayInput(int[][] inputData);<br \/>\npublic native int[] returnArray(int[] inputData2);<br \/>\n[\/java]<\/p>\n<p>\u4e8c\u7dadint\u9663\u5217\u50b3\u503c\uff1a<br \/>\n[java]<br \/>\npublic final static int[][] inputData = {<br \/>\n                                       {0x0226,0x00}<br \/>\n                                      ,{0x0227,0x40}<br \/>\n                                      ,{0x0228,0x00}<br \/>\n                                    };<br \/>\nJniTest jnitest = new JniTest();<br \/>\njnitest.2DArrayInput(inputData);<br \/>\n[\/java]<br \/>\n<!--more--><br \/>\n\u4e0b\u5c64C\/C++\u64b0\u5beb\uff0c\u8f49\u63db\u6210JNI\u51fd\u5f0f\u9019\u88e1\u6211\u5c31\u4e0d\u4ecb\u7d39\uff0c\u8acb\u53c3\u8003-<a href=\"https:\/\/learn-house.idv.tw\/?p=3482\">[Android]\u5982\u4f55\u5728AOSP\u4e0b\u7de8\u8b6fJNI<\/a><br \/>\n[c]<br \/>\nJNIEXPORT void JNICALL Java_com_example_jni_JniTest_2DArrayInput (JNIEnv *env, jobject, jobjectArray inputData) {<br \/>\n\tint len = env-&gt;GetArrayLength(inputData);<br \/>\n\tjint qizi[len][2];<br \/>\n\tjobject datas;<\/p>\n<p>\tfor (int i = 0; i &lt; len; i++) {<br \/>\n\t\tdatas = (env-&gt;GetObjectArrayElement(inputData, i));<br \/>\n\t\tint num = env-&gt;GetArrayLength((jarray)datas);<br \/>\n\t\tjint *data = env-&gt;GetIntArrayElements((jintArray)datas, 0);<br \/>\n\t\tfor (int j = 0; j &lt; num; j++) {<br \/>\n\t\t\tqizi[i][j] = data[j];<br \/>\n\t\t\tALOGD(&quot;Show data:%d&quot;, qizi[i][j]);<br \/>\n\t\t}<br \/>\n\t\tenv-&gt;ReleaseIntArrayElements((jintArray)datas, data, 0);<br \/>\n\t}<br \/>\n}<br \/>\n[\/c]<\/p>\n<p>\u4e00\u7dadint\u9663\u5217\u50b3\u503c\u8207\u9663\u5217\u56de\u50b3\uff1a<br \/>\n[java]<br \/>\nint[] inputData2 = {0, 1, 2, 3, 4};<br \/>\n&#8230;(\u7565)<br \/>\njnitest.arrayInput(inputData2);<br \/>\n[\/java]<br \/>\nJNI\u5c64\uff1a<br \/>\n[c]<br \/>\nJNIEXPORT void JNICALL Java_com_arcadyan_jni_JniTest_returnArray (JNIEnv *env, jobject, jintArray array) {<br \/>\n\tjsize size = env-&gt;GetArrayLength(array);<br \/>\n\tjint *intArray= env-&gt;GetIntArrayElements(array, 0);<br \/>\n\tfor (int i = 0; i &lt; size; i++) {<br \/>\n\t\tintArray[i] += 1;<br \/>\n\t}<br \/>\n\tjintArray newIntArray = env-&gt;NewIntArray(size);<br \/>\n\t\/\/\u628ajint\u6307\u6a19\u4e2d\u7684\u5143\u7d20\u8a2d\u5b9a\u5230jintArray\u7269\u4ef6\u4e2d<br \/>\n\tenv-&gt;SetIntArrayRegion(newIntArray, 0, size, intArray);<br \/>\n\treturn newIntArray;<br \/>\n}<br \/>\n[\/c]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0a\u5c64Java\u547c\u53ebC\/C++\u7684\u51fd\u5f0f [java] public native void 2DArrayInput<span class=\"post-excerpt-end\">&hellip;<\/span><\/p>\n<p class=\"more-link\"><a href=\"https:\/\/learn-house.idv.tw\/?p=3506\" class=\"themebutton\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-3506","post","type-post","status-publish","format-standard","hentry","category-5"],"_links":{"self":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/3506","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3506"}],"version-history":[{"count":0,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/3506\/revisions"}],"wp:attachment":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3506"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3506"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3506"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}