【发布时间】:2020-06-11 17:07:12
【问题描述】:
我知道可以从 AssetFileDescriptor 内容中读取文件,例如偏移量和长度。我通过以下方式传递给 JNI 数据:
val resources = context.get()!!.resources
val file = resources.openRawResourceFd(rawFileId) // example: R.raw.you_file
val fileOffset = file.startOffset.toInt()
val fileLength = file.length.toInt()
try {
file.parcelFileDescriptor.close()
} catch (e: IOException) {
Log.e("error", "Couldn't close")
}
try {
this.id = ndkJNIBind(
context.get()!!.packageResourcePath, fileLength, fileOffset)
} catch (e: UnsatisfiedLinkError) {
Log.e("error", "Couldn't do ndkJNIBind")
}
现在,在 NDK 端如何读取文件?
extern "C" JNICALL JNIEXPORT
void Java_package_TheClass_ndkJNIBind(
JNIEnv* env,
jobject __unused,
jstring path,
jint fileLength,
jint fileOffset
) {
// TODO: ??????
}
【问题讨论】:
标签: android android-ndk