title: Android - writing/saving files from native code only
body: <p>I'm trying to build an Android app which makes use of the <code>NativeActivity</code> facility of the NDK.
  I'm having the following structure:</p>
  
  <ul>
  <li>a bunch of native shared libraries installed in <code>/system/vendor/&lt;company&gt;</code>; I'm working
  with a custom built Android image so there's no problem having the libraries there with
  proper permissions and everything</li>
  <li>a couple of applications using the <code>NativeActivity</code> that depend in turn on the libraries
  mentioned above</li>
  </ul>
  
  <p>The libraries installed in the /system/vendor and my applications use a couple of
  configuration files. There's no problem reading them using the standard C API
  <code>fopen/fclose</code>. But those libraries and my application also need to store some files
  as the result of their operation, like configuration, some run-time parameters, calibration
  data, log files etc. With the storing of the files there is a slight issue as I'm not allowed to write into <code>/system/vendor/...</code> (as the file system under "/system/..." is mounted read-only and I do not want to hack on that).</p>
  
  <p>So what would be the best way to create and store those files and where would be the
  best "conforming with Android" storage area ?</p>
  
  <p>I've been reading a couple of threads in the android-ndk Google group and here on SO that mention either <a href="https://stackoverflow.com/questions/6525724/how-do-i-write-to-the-internal-storage-file-system-with-nativeactivity">the internal application private storage</a> or <a href="https://stackoverflow.com/questions/1992953/file-operations-in-android-ndk">the external SD card</a>, but as I do not have extended experience with Android I'm not sure what would be the proper approach. If the approach involves some specific Android API a small code example in C++ would be very helpful; I've seen a couple of examples involving Java and JNI (<a href="https://stackoverflow.com/questions/4731314/android-ndk-write-file">e.g. in this SO question</a>) but I would like to stay away from that right now.
  Also there seems to be a problem with using from C++ the native activity's
  <code>internalDataPath/externalDataPath</code> pair (<a href="https://stackoverflow.com/questions/10683119/android-app-activity-internaldatapath-still-null-in-2-3-8-ndk-r8?lq=1">a bug that makes them be always NULL</a>).</p>