Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Assets and NDK

Tags:

android-ndk

I'm trying to read a simple text file from my native code.

  1. I placed file.txt under assets folder
  2. 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?

like image 642
nmnir Avatar asked Mar 01 '12 12:03

nmnir


1 Answers

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.

like image 123
Mārtiņš Možeiko Avatar answered Sep 28 '22 05:09

Mārtiņš Možeiko