Drive for better visionAndroid JNI (2)March, 2012                      Himax Media                      Solutions         ...
JNI 存取 Java Object Field             jclass clazz = env-              >FindClass("android/view/Surface")                ...
Java Class                           int mObject                                       call               call            ...
JNI 呼叫 Java Callback           jclass clazz = env->FindClass("class name")           methodId = env->GetStaticMethodID(c...
JNI 產生 Java Object             建立 object                   mRectClass = env->FindClass("android/graphics/Rect")         ...
Drive for better vision
Upcoming SlideShare
Loading in...5
×

12 android jni(2)

471

Published on

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
471
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "12 android jni(2)"

  1. 1. Drive for better visionAndroid JNI (2)March, 2012 Himax Media Solutions 承景科技股份有限公司
  2. 2. JNI 存取 Java Object Field  jclass clazz = env- >FindClass("android/view/Surface")  找到 class 名稱對應的 jclass 型態  jfieldID field = env->GetFieldID(clazz, "left", "I")  left 是整數型態的 class member ,取得其 field ID  jint i = env->GetIntField(thiz, field)  thiz 是一個屬於 clazz 類別的物件  取得 thiz 物件中 field ID 指定的 class member  env->SetIntField(thiz, field, value)  設定 thiz 物件的 field 值為 valueHimax Media Solutions Proprietary & Confidential 2
  3. 3. Java Class int mObject call call function function init convert without with class pointer mObject mObject to integer JNI Class *c = reinterpret_cast<Class *>(obj) Class *c = reinterpret_cast<Class *> (env->GetIntField(thiz, mObjectID)) create class use object object use pointer object C++ ClassHimax Media Solutions Proprietary & Confidential 3
  4. 4. JNI 呼叫 Java Callback  jclass clazz = env->FindClass("class name")  methodId = env->GetStaticMethodID(clazz, "FuncName", "(I)V");  取得 void FuncName(int) 的 id  env->CallStaticVoidMethod(clazz, methodId, intValue);Himax Media Solutions Proprietary & Confidential 4
  5. 5. JNI 產生 Java Object  建立 object  mRectClass = env->FindClass("android/graphics/Rect")  consId = env->GetMethodID(mRectClass, "<init>", "()V");  jobject rect = env->NewObject(mRectClass, consId)  刪除 object  env->DeleteLocalRef(rect)  存取 object field  jfieldID field = env->GetFieldID(mRectClass, "FieldName", "I")  env->SetIntField(rect, field, value);Himax Media Solutions Proprietary & Confidential 5
  6. 6. Drive for better vision

×