Код: Выделить всё
AAsset* pAsset = AAssetManager_open(pAssetManager, "asset_test.txt", AASSET_MODE_STREAMING);
DebugPrint(pAsset?"pAsset not NULL\n":"pAsset NULL");
if (pAsset)
{
char buf[1024];
AAsset_read(pAsset, buf, sizeof(buf));
DebugPrint(buf);
AAsset_close(pAsset);
}
Я поместил файл assets_test.txt в свой каталог ресурсов и заглянул в .apk, чтобы убедиться, что он существует, переименовав .apk в .zip и открыв его с помощью 7zip.
У меня есть еще код:
Код: Выделить всё
AAssetDir* pAssetDir = AAssetManager_openDir(pAssetManager, sDirectory.c_str());
if (!pAssetDir)
{
DebugPrint("pAssetDir NULL\n");
return;
}
const char* pszDir;
while ((pszDir = AAssetDir_getNextFileName(pAssetDir)) != NULL)
{
DebugPrint(pszDir);
}
AAssetDir_close(pAssetDir);
Примечание. DebugPrint — это просто более красивая оболочка вокруг __android_log_print().
Подробнее здесь: https://stackoverflow.com/questions/224 ... rning-null
Мобильная версия