Implement native file loading on Android using AndroidAssetManager
In C++, files can't be accessed locally. They're stored in the apk and need to be accessed vis AndroidAssetManager. https://developer.android.com/ndk/reference/group/asset
To create a local assetmanager, several things are needed.
- We need a "JNIEnv" variable to get a handle to Asset manager.
Some thing like:
void Java_com_example_android_livecubes_cube1_CubeWallpaper1_load
(JNIEnv *env, jobject obj, jobject assetManager)
see first link below.
- We need to wrap our FileSystem functions around AndroidAssetManager
Helpful links: https://stackoverflow.com/questions/13317387/how-to-get-file-in-assets-from-android-ndk/13317651#13317651
https://stackoverflow.com/questions/10941802/cant-access-aassetmanager-in-native-code-passed-from-java-in-wallpaperservice/11617834#11617834
See also this project: akk0rd87 implemented a wrapper for both android and iOS native functions.
https://bitbucket.org/akk0rd87/akk0rdsdk/src/master/
Also, there seems to be SDL functionality for this: https://wiki.libsdl.org/SDL_AndroidGetJNIEnv
JNIEnv* env = (JNIEnv*)SDL_AndroidGetJNIEnv();
jobject activity = (jobject)SDL_AndroidGetActivity();
jclass activity_class = env->GetObjectClass(activity);
jmethodID activity_class_getAssets = env->GetMethodID(activity_class, "getAssets", "()Landroid/content/res/AssetManager;");
jobject asset_manager = env->CallObjectMethod(activity, activity_class_getAssets); // activity.getAssets();
global_asset_manager = env->NewGlobalRef(asset_manager);
pAssetManager = AAssetManager_fromJava(env, global_asset_manager);