How do you access an Android asset, such as a .txt file, from C with the JNI?
I'm trying "file:///android_asset/myFile.txt", and locally "myFile.txt" with a duplicate of myFile.txt in the jni folder with the C implementation file.
The thing with assets is that you can't access them directly as files. This is because the assets are read directly from the APK. They're not unzipped to a given folder upon installation.
Starting from Android 2.3, there is a C API to access assets. Have a look at <android/asset_manager.h>
and the assetManager
field in <android/native_activity.h>
. I've never used this though, and I'm not sure that you can use this asset manager API if you don't rely on a native activity. And anyway, this won't work on Android 2.2 and below.
So I see three options:
InputStream
object returned by AssetManager.open()
. It takes a little code but it works great.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With