Android and NDK Assets

I am trying to read a simple text file from my own code.

  • I put the file.txt file in the resource folder
  • In my activity I create an asset manager: assetManager = getAssets(); Then I pass the resourceManager to my own method and (as in the example with the native sound):

     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 less than 0 !!!

Can anyone help with this?

+6
source share
1 answer

AAsset_openFileDescriptor will only work with files that are not compressed (e.g. mp3, jpg, png, etc.). It is written in the 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 .

+5
source

Source: https://habr.com/ru/post/909734/


All Articles