1

I wrote a small test application that uses SDL2 on Android via the NDK. It compiles and runs. However, as soon as I try to open files I get FileNotFound Exceptions. I added an assets Directory in my eclipse workdir and put files inside it. When I Export the projekt to an .apk, I can open the file in 7z and see that there is an assets Directory with those files in it. However, when the code gets executed and I try to open assets/somefile.txt, I get a FileNotFound Exception.

Google so far told me that I could put an sdcard in my device with those files on it and access it through /sdcard/ . I'ld like to include those files in my apk though.

How do I Access the files I put in assets ? Or where should I put those files and how should I adjust my path it can Access them at runtime?

marc40000
  • 3,167
  • 9
  • 41
  • 63
  • 1
    It's not a duplicate of the one mvp suggested as that questions relates to Java/SDK and mine to C(++)/NDK. – marc40000 Nov 07 '14 at 01:31
  • Indeed it is not, but it is a duplicate of the NDK question. Fundamentally, apk contents are not file system files, so your choices are basically using the assets api or parsing the .apk zip structure yourself. – Chris Stratton Nov 07 '14 at 02:44

1 Answers1

-1

Place this code before anything else in your main activity ->

 if (Environment.getExternalStorageState (). equals (Environment.MEDIA_MOUNTED)) {
 File directory = new File (Environment.getExternalStorageDirectory () + + File.separator    "YourFolderName");
 directory.mkdirs ();

   }

Give this permission in the Manifest xml ->

  <uses-permission android: name = "android.permission.WRITE_EXTERNAL_STORAGE" />
Kamuy
  • 177
  • 1
  • 6
  • What exactly does this do? Does it extract the files from the apk to the external storage? – marc40000 Nov 07 '14 at 01:32
  • This is the first step. Makes you create a directory so that the user instalae your application on the device. Now, you put the files into sdcard / yourfolder. You have to explain what kind of performance will make your app. How do you want to open this file. For you open an image, for example, need a Image view Text view and to open a TXT text. – Kamuy Nov 07 '14 at 02:11
  • This does not answer the question which was asked. – Chris Stratton Nov 07 '14 at 02:46