如何将Android Surface对象转换为本机表面

时间:2014-07-01 15:52:45

标签: android android-ndk java-native-interface surfaceview

我目前在我的JNI代码中使用android_view_Surface_getSurface()来从Java Surface对象获取本机Surface。这似乎适用于Android 4.4设备,但不适用于具有较旧操作系统版本的设备,例如我使用4.1测试,看起来像系统库中缺少符号android_view_Surface_getSurface。

是否有适用于所有设备的方法? (或至少4+)。如果没有,如何只针对较旧的OS版本执行此操作?

谢谢, 武

1 个答案:

答案 0 :(得分:2)

您将其作为公共API。

/**
 * Return the ANativeWindow associated with a Java Surface object,
 * for interacting with it through native code.  This acquires a reference
 * on the ANativeWindow that is returned; be sure to use ANativeWindow_release()
 * when done with it so that it doesn't leak.
 */
ANativeWindow* ANativeWindow_fromSurface(JNIEnv* env, jobject surface);

参见此处的示例: Application crashing due to use of ANativeWindow API