3
3
#include < jni.h>
4
4
#include < string>
5
5
#include " android/log.h"
6
+ #include < sys/system_properties.h>
7
+
6
8
extern " C"
7
9
8
10
// JNIEXPORT jstring JNICALL
@@ -16,7 +18,7 @@ extern "C"
16
18
17
19
JNIEXPORT jfloatArray JNICALL
18
20
Java_cookbook_testjni_MainActivity_setFloatArray (
19
- JNIEnv * env,
21
+ JNIEnv *env,
20
22
jobject thiz,
21
23
jfloatArray fArray ) {
22
24
@@ -28,27 +30,27 @@ Java_cookbook_testjni_MainActivity_setFloatArray(
28
30
// jchar *jcharBuffer;
29
31
// env->GetStringRegion(jstring1,0,3,jcharBuffer);
30
32
31
- int fLength = env->GetArrayLength (fArray );
32
- const float * floatArray = env->GetFloatArrayElements (fArray ,0 );
33
+ int fLength = env->GetArrayLength (fArray );
34
+ const float *floatArray = env->GetFloatArrayElements (fArray , 0 );
33
35
34
- for (int i= 0 ;i< fLength ;i++){
35
- __android_log_print (ANDROID_LOG_ERROR," andymao" ," for loop item=%d,i=%d" ,*floatArray,i);
36
- }
36
+ for (int i = 0 ; i < fLength ; i++) {
37
+ __android_log_print (ANDROID_LOG_ERROR, " andymao" , " for loop item=%d,i=%d" , *floatArray, i);
38
+ }
37
39
38
- Test test (1 ,3 , 5 );
39
- test.setTransforamMatrix (floatArray);
40
+ Test test (1 , 3 , 5 );
41
+ test.setTransforamMatrix (floatArray);
40
42
41
43
// int aaa[5] = { 1, 2, 3, 4, 5};
42
44
//
43
45
// for(int j=0;j<5;j++){
44
46
// __android_log_print(ANDROID_LOG_ERROR,"andymao","for loop item=%d,j=%d",aaa[j],j);
45
47
// }
46
48
47
- int newLength = fLength + 2 ;
48
- jfloatArray jfloatArray1 = env->NewFloatArray (newLength);
49
+ int newLength = fLength + 2 ;
50
+ jfloatArray jfloatArray1 = env->NewFloatArray (newLength);
49
51
// env->SetFloatArrayRegion(jfloatArray1,0,fLength,floatArray);
50
52
51
- return jfloatArray1;
53
+ return jfloatArray1;
52
54
53
55
}
54
56
@@ -58,4 +60,55 @@ Java_cookbook_testjni_MainActivity_setFloatArray(
58
60
//
59
61
//
60
62
// }
63
+ void fillIntArray (jint*& array) {
64
+ jint *fkJintArray = new jint[12 ];
65
+ for (int i = 0 ; i < 12 ; ++i) {
66
+ fkJintArray[i] = i;
67
+ }
68
+
69
+ array = fkJintArray;
70
+ }
71
+ /* *
72
+ * http://androidxref.com/4.3_r2.1/xref/frameworks/base/opengl/java/android/opengl/EGLContext.java
73
+ * http://androidxref.com/4.4_r1/xref/frameworks/base/opengl/java/android/opengl/EGLContext.java
74
+ *
75
+ * https://developer.android.com/reference/android/opengl/EGLObjectHandle.html#getHandle()
76
+ * Use getNativeHandle() instead. Handles on 64 bit platforms will be wider than java ints.
77
+ */
78
+ extern " C"
79
+ JNIEXPORT void JNICALL
80
+ Java_cookbook_testjni_MainActivity_getIntArray (JNIEnv *env, jobject instance,
81
+ jintArray intArrays_) {
82
+ __android_log_print (ANDROID_LOG_ERROR, " andymao" , " 111" );
83
+ jclass eglcontextClassLocal = env->FindClass (" android/opengl/EGLContext" );
84
+ jmethodID eglcontextConstructor;
85
+ jobject jobject1;
86
+ try {
87
+ __android_log_print (ANDROID_LOG_ERROR, " andymao" , " xxxx" );
88
+ eglcontextConstructor=env->GetMethodID (eglcontextClassLocal, " <init>" , " (J)V" );
89
+ __android_log_print (ANDROID_LOG_ERROR, " andymao" , " xxxx222" );
90
+ jobject1 = env->NewObject (eglcontextClassLocal, eglcontextConstructor,
91
+ reinterpret_cast <jlong>(jlong (10000 )));
92
+ __android_log_print (ANDROID_LOG_ERROR, " andymao" , " 333" );
93
+ }catch (...){
94
+ __android_log_print (ANDROID_LOG_ERROR, " andymao" , " 111--->111" );
95
+ eglcontextConstructor=env->GetMethodID (eglcontextClassLocal, " <init>" , " (I)V" );
96
+ jobject1 = env->NewObject (eglcontextClassLocal, eglcontextConstructor,
97
+ reinterpret_cast <jlong>(jlong (10000 )));
98
+ }
99
+
100
+ __android_log_print (ANDROID_LOG_ERROR, " andymao" , " 222" );
101
+
102
+
103
+
104
+ __android_log_print (ANDROID_LOG_ERROR, " andymao" , " kkkkkkkk" );
105
+
106
+ jint *intArrays = env->GetIntArrayElements (intArrays_, NULL );
107
+
108
+ fillIntArray (intArrays);
109
+
110
+ env->ReleaseIntArrayElements (intArrays_, intArrays, 0 );
111
+ }
112
+
113
+
61
114
0 commit comments