I'm trying to read a simple text file from my native code.
In my activity I'm creating asset manager: assetManager = getAssets();
Then I'm passing the assetManager to my native method and(as in the native audio example):
AAssetManager* mgr = AAssetManager_fromJava(env, assetManager);
AAsset* asset = AAssetManager_open(mgr, "file.txt", AASSET_MODE_UNKNOWN);
AAssetManager* mgr = AAssetManager_fromJava(env, assetManager);
off_t start, length;
int fd = AAsset_openFileDescriptor(asset, &start, &length);
The problem is that fd
is smaller than 0!!!
Can anyone help on this?
AAsset_openFileDescriptor
will work only with files that are not compressed (like mp3,jpg,png, etc...). It's written in documentation (asset_manager.h header file):
/**
* Open a new file descriptor that can be used to read the asset data.
*
* Returns < 0 if direct fd access is not possible (for example, if the asset is
* compressed).
*/
int AAsset_openFileDescriptor(AAsset* asset, off_t* outStart, off_t* outLength);
Use either AAsset_read
or AAsset_getBuffer
.
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