I need to check wether a certain directory exists in apk.
The android/asset_manager.h
api seems to be inconsistent - it returns NULL when AAsset* AAssetManager_open(AAssetManager* mgr, const char* filename, int mode);
fails to open a file, but for directories AAssetDir* AAssetManager_openDir(AAssetManager* mgr, const char* dirName);
's implementation always returns a new AAssetDir(...)
, even if internally it failed to open/find the directory in apk.
It is quite irritating that AAssetDir
is forward-declared and it's implementation is hidden away in the .cpp file, otherwise it would've been (maybe?)possible to check the internal AssetDir
object for validity.
There is another option I am exploring right now - to call java and do something like:
public static boolean folderExistsInApk(final String path){
AssetManager assetManager = activity.getAssets();
try{
//if .list would fail, it would throw IOException
//which would signal that there is no such directory
assetManager.list(path);
}catch(Exception e){
return false;
}
return true;
}
But it seems "dirty" to me, and it would definitely be pretty slow (which isn't a big factor in my specific code, but still - avoiding unnecessary pessimisation is good coding practice).
Have I missed something? Is it possible to check if directory exists in apk via native code only? If not - how to best do it with jni?