accessing file on sdcard android

北慕城南 提交于 2019-12-08 18:49:33

Try

Environment.getExternalStorageDirectory()

to get the root of the sd-card.

@sanna is correct that you should use Environment.getExternalStorageDirectory(), however, I would suggest first using Environment.getExternalStorageState()to determine if you are able to access the storage - for instance, in your example, when the SD card is mounted on the PC.

On my device the external sd data is in a further directory called 'external_sd'. Environment.getExternalStorageDirectory() gives the root directory for the sd card, but if you placed data on your device from a computer, it may be in "file://"+Environment.getExternalStorageDirectory()+"/external_sd/"

This was only obvious by using the 'My Files' app on the device, the external_sd directory level is not apparent when mounted on a computer via USB.

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