Creating temporary files in Android with NDK

前端 未结 5 1442
一生所求
一生所求 2020-12-03 07:10

I am currently working on a C-based, NDK-based, Android application. This application needs to create temporary files. On a regular Linux system, I would use tmpfile

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-03 07:49

    The best way we've found is to call Context.getCacheDir on startup, get its path with getAbsolutePath, then call a JNI function to store that path in a global. Any function that wants to create a temporary file simply appends a suitable temporary file name to that path.

    If you really want to fetch it from JNI another alternative would be to pass in a Context to a JNI function and use a bunch of GetMethodID / CallObjectMethod stuff to call back into Java to getCacheDir, but the former approach is a lot simpler.

    Unfortunately, there does not appear to be a more elegant solution at the moment.

提交回复
热议问题