I’m trying to read a simple text file from my native code.
- I placed file.txt under assets folder
-
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_openFileDescriptorwill work only with files that are not compressed (like mp3,jpg,png, etc…). It’s written in documentation (asset_manager.h header file):Use either
AAsset_readorAAsset_getBuffer.