I have an app which saves backup files on SD-Card. It works fine on HTC Nexus One, and other android phones, but with some phones it doesn\'t work (reading or writing).
When you say "it doesn't work".... what exactly happens? Do you mean the program runs without complaint but the file doesn't get written to the sdcard, or do you mean something else?
If the file is simply not getting there, it's not your fault, it's the phone manufacturer's fault. I've seen several devices that return "/mnt/sdcard" from getExternalStorageDirectory(), however this is not truly the path to the sdcard! On at least one Motorola device and on the Samsung Galaxy Tab (7"), for example, /mnt/sdcard is returned even though this points to internal storage, and the external storage on each of these devices is /mnt/sdcard-ext.
There's nothing legitimately you can do about this -- the OEM is lying to you. If you want a hack of a work-around, you can read /proc/mounts and try to find the actual path to the sdcard, but /mnt/sdcard will also show up there, and there's no guaranteed way to distinguish the truth for all devices.
I have Sony Xperia tipo dual and this:
FILE* pFile = fopen("/mnt/sdcard/mydata.dat","w+");
and this:
FILE* pFile = fopen("/sdcard/mydata.dat","w+");
Both work ok. (I did it in Native)
Generally, Android wouldn't allow you to write a file directly to the SDCard's root. You must create a folder in the SDCard root, and then write your file inside the newly created folder.
Try this, and it should work.