转自:http://www.cppblog.com/johndragon/archive/2012/12/28/196754.html
在Android ndk api level 9 之后,提供了一套称为 AssetManager 的api。
static AAssetManager * gAssetMgr = NULL; extern "C" { void Java_org_cocos2dx_lib_Cocos2dxActivity_nativeSetAssetManager(JNIEnv* env, jclass cls, jobject assetManager) { gAssetMgr = AAssetManager_fromJava( env, assetManager ); } };
读取资源的方法如下
do{ AAsset * pAsset = AAssetManager_open(gAssetMgr, pszFileName, AASSET_MODE_UNKNOWN); if( pAsset == NULL ) break; size_t size = AAsset_getLength(pAsset); if( size > 0 ) { pData = new unsigned char[size]; int iRet = AAsset_read( pAsset, pData, size); if( iRet <= 0 ) { delete [] pData; pData = NULL; } } AAsset_close(pAsset); if( pAsset == NULL ) size = 0; if( pSize ) *pSize = size; } while(0);
Android ndk下用AssetManager读取assets的资源,布布扣,bubuko.com
Android ndk下用AssetManager读取assets的资源
原文:http://www.cnblogs.com/sevenyuan/p/3708004.html