User Tools

Site Tools


android:tips

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
android:tips [2017/02/14 10:41] – created orelandroid:tips [2024/03/18 15:06] (current) – external edit 127.0.0.1
Line 8: Line 8:
  
 <code C testasset.c> <code C testasset.c>
-#include "SDL_system.h"+#include "SDL_system.h"  // TRY DONT USE THIS
 #include <jni.h> #include <jni.h>
 #include <android/asset_manager.h> #include <android/asset_manager.h>
Line 14: Line 14:
  
 // retrieve the JNI environment. // retrieve the JNI environment.
-JNIEnv* jnienv = (JNIEnv*)SDL_AndroidGetJNIEnv();+JNIEnv* jnienv = (JNIEnv*)SDL_AndroidGetJNIEnv();   // REPLACE THIS
 int version = (*jnienv)->GetVersion(jnienv); int version = (*jnienv)->GetVersion(jnienv);
-SDL_Log("version %d\n", version);+// SDL_Log("version %d\n", version);
  
 // retrieve the Java instance of the SDLActivity // retrieve the Java instance of the SDLActivity
-jobject activity = (jobject)SDL_AndroidGetActivity();+jobject activity = (jobject)SDL_AndroidGetActivity();  // REPLACE THIS
  
 // find the Java class of the activity. It should be SDLActivity or a subclass of it. // find the Java class of the activity. It should be SDLActivity or a subclass of it.
Line 45: Line 45:
 // SDL_Log("fd = %d\n", fd); // 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(activity);
Line 55: Line 72:
   * https://developer.android.com/ndk/reference/group___asset.html   * https://developer.android.com/ndk/reference/group___asset.html
   * https://wiki.libsdl.org/CategorySystem   * https://wiki.libsdl.org/CategorySystem
 +  * https://wiki.libsdl.org/SDL_RWops
   * https://en.wikibooks.org/wiki/OpenGL_Programming/Android_GLUT_Wrapper   * https://en.wikibooks.org/wiki/OpenGL_Programming/Android_GLUT_Wrapper
android/tips.1487068909.txt.gz · Last modified: 2024/03/18 15:04 (external edit)