I have kept some files in assets folder of android application.
Now i compile that application and get apk. [when i extract that apk my files are there in assets folder]
Now i install that apk in mobile device
and in That application has some code in c programing with JNI interface.
Now my fopen()
call in c programming for that file get failed.
fopen("myfile","r");
I know while installing apk android copy assets file to /data/data/com.packagename/something
So does anyone knows that path so i can give it in fopen()
or is there any other method to open that file in C programming.
If i keep those files in sdcard folder and access like fopen("/sdcard/myfile","r");
then it works file. But i want to keep those files in assets folder only
You can use the asset manager to access assets in JNI code. It's part of NDK.
http://developer.android.com/ndk/reference/group___asset.html
Something like:
EXPORT_API void LoadAsset(char* filename, jobject assetManager){
AAssetManager* mgr = AAssetManager_fromJava(env, assetManager);
AAsset* asset = AAssetManager_open(mgr, filename, AASSET_MODE_BUFFER);
AAsset_read(asset, ...);
}
And then in Java something like:
LoadAsset("myfile", getContext().getAssetManager());
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