Unable to write files on sdcard android

佐手、 提交于 2019-11-29 04:33:34

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.

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.

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)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!