Can't access the secondary storage (the external removable micro sd card)

左心房为你撑大大i 提交于 2019-11-28 14:46:50

My problem is that I can write to the "real internal storage card" (the phone's sd card) but not to the "real external storage card" (the removable micro sd card)

That's been the case since Android 4.4, released about four years ago.

But I need to write files on the micro sd card.

You can use getExternalFilesDirs(), getExternalCacheDirs(), and getExternalMediaDirs() on Context. Note the plural form of these method names. If these return 2+ items, the second and subsequent ones are locations on removable storage, unique to your app, that you can read from and write to.

Alternatively, use the Storage Access Framework and let the user choose where to put the content, where you use the resulting Uri with ContentResolver and openOuptutStream() to write to that location. This would allow the user to work with external storage, removable storage, plus locations supported by third-party apps (Google Drive, SMB/CIFS file servers, etc.).

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