Hi,
Well, I had absolutely no problems doing that from C code by regular
open/read/write/close functions; C++ must be the same (e. g. this very
dumb logging function):
void jnilog(char *str) {
int fd = open("/system/media/sdcard/jni.log", O_RDWR | O_APPEND |
O_CREAT, 0666);
if(fd > -1) {
write(fd, str, strlen(str));
write(fd, "\n", 1);
close(fd);
}
}
Path to the file may be more configurable: in Java code you call
getExternalStorageDirectory() to obtain the SD card path that is known
to the system, and pass it to the native code. In fact /system/media/
sdcard will likely be the path to the "resident" storage device (at
least in my case, where files uploaded via USB end up, even when the
removable sdcard is not inserted).
Permission-wise, make sure you include in your AndroidManifest.xml
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> somewhere
inside the <manifest> tag.
When installing your apk, you will see the warning that the
application wants to modify external storage; this means that your
request for permissions in the manifest xml was understood.
Also note that filesystem on the sdcard is most likely FAT32 (does not
distinguish between characters case in filenames).
Hope this helps.