Search code examples
androidsdlapk

SDL - android port - how to open image in apk file from c code?


Can somebody give an example of opening asset file in apk, which is called from native code? SDL 1.3 have "Android_JNI_FileOpen()" function, but I can't understand how to use it.


Solution

  • Actually what you need to do is to create SDL_RWops from file - on Android file is taken from apk. So simple.

    Old code:

    /* Load graphics */
    image = IMG_Load("/sdcard/imagename.type");
    

    New code:

    /* Load graphics */
    SDL_RWops *file = SDL_RWFromFile("imagename.type", "rb");
    image = IMG_Load_RW(file, 1);
    

    P.S. File must be in "assets" directory in apk.