char* Get_Surface(JNIEnv *env, jclass cls, jobject param, int sdk_version)
{
// Java层
jfieldID surface = env->GetFieldID(cls, "mSurface", "Landroid/view/Surface;");
jobject surface_cls = env->GetObjectField(param, surface);
// Native层
jclass surface_class = env->FindClass("android/view/Surface");
jfieldID surface_native = env->GetFieldID(surface_class, "mSurface", "I"); //"I"指整型
// the JNI also supports other functions such as GetIntField and SetFloatField for accessing instance fields of primitive types.
return (char*)(Surface*)env->GetIntField(surface_cls, surface_native);
}
Once you have obtained the field ID, you can pass the object reference and the field ID to the appropriate instance field access function:
jstr = (*env)->GetObjectField(env, obj, fid);
{
// Java层
jfieldID surface = env->GetFieldID(cls, "mSurface", "Landroid/view/Surface;");
jobject surface_cls = env->GetObjectField(param, surface);
// Native层
jclass surface_class = env->FindClass("android/view/Surface");
jfieldID surface_native = env->GetFieldID(surface_class, "mSurface", "I"); //"I"指整型
// the JNI also supports other functions such as GetIntField and SetFloatField for accessing instance fields of primitive types.
return (char*)(Surface*)env->GetIntField(surface_cls, surface_native);
}
理解GetIntField
(char*)(Surface*)env->GetIntField(surface_cls, surface_native);Once you have obtained the field ID, you can pass the object reference and the field ID to the appropriate instance field access function:
jstr = (*env)->GetObjectField(env, obj, fid);
本文深入探讨JNI中关于Surface的参数传递,重点解析GetIntField方法的使用,揭示其在JNI与Java层交互中的关键作用。
9630

被折叠的 条评论
为什么被折叠?



