#include "SDL_system.h" // TRY DONT USE THIS #include #include #include // retrieve the JNI environment. JNIEnv* jnienv = (JNIEnv*)SDL_AndroidGetJNIEnv(); // REPLACE THIS int version = (*jnienv)->GetVersion(jnienv); // SDL_Log("version %d\n", version); // retrieve the Java instance of the SDLActivity jobject activity = (jobject)SDL_AndroidGetActivity(); // REPLACE THIS // find the Java class of the activity. It should be SDLActivity or a subclass of it. jclass activityclass = (*jnienv)->GetObjectClass(jnienv, activity); /* context = SDLActivity.getContext(); */ jmethodID mid = (*jnienv)->GetStaticMethodID(jnienv, activityclass, "getContext","()Landroid/content/Context;"); jobject context = (*jnienv)->CallStaticObjectMethod(jnienv, activityclass, mid); jclass contextclass = (*jnienv)->GetObjectClass(jnienv, context); /* assetManager = context.getAssets(); */ mid = (*jnienv)->GetMethodID(jnienv, contextclass, "getAssets", "()Landroid/content/res/AssetManager;"); jobject assetmanager = (*jnienv)->CallObjectMethod(jnienv, context, mid); // finally get AAssetManager instance AAssetManager* mgr = AAssetManager_fromJava(jnienv, assetmanager); if(!mgr) ERROR("Fail to get AAssetManager\n"); AAsset* asset = AAssetManager_open(mgr, "game_easy.txt", AASSET_MODE_UNKNOWN); if(!asset) ERROR("Fail to get file %s from Assets\n", "game_easy.txt"); /* AAsset_openFileDescriptor() only works with uncompressed files as mp3, png, ... */ // off_t start, length; // int fd = AAsset_openFileDescriptor(asset, &start, &length); // SDL_Log("fd = %d\n", fd); /* Use either AAsset_read or AAsset_getBuffer. */ // copy all files on local storage */ AAssetDir* assetDir = AAssetManager_openDir(mgr, ""); const char* filename = (const char*)NULL; while ((filename = AAssetDir_getNextFileName(assetDir)) != NULL) { AAsset* asset = AAssetManager_open(mgr, filename, AASSET_MODE_STREAMING); char buf[BUFSIZ]; int nb_read = 0; FILE* out = fopen(filename, "w"); while ((nb_read = AAsset_read(asset, buf, BUFSIZ)) > 0) fwrite(buf, nb_read, 1, out); fclose(out); AAsset_close(asset); } AAssetDir_close(assetDir); // env->DeleteLocalRef(activity); // env->DeleteLocalRef(activityclass);