微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 无法访问辅助存储(外部可移动micro sd卡)

在阅读真实问题之前,请先阅读我的问题介绍:

In Android there are an internal storage and an external storage.
Don’t be confused, because the internal storage relates to files that are accessible only by the app, and the external storage relates to normal files that can be accessed by all apps and can be found both in the real internal storage card (the phone’s sd card) and in the real external storage card (the removable micro sd card).

My path of the phone’s sd card (the one that you can’t remove) is: /storage/emulated/0.
My path of the micro sd card (the one that you can insert or remove) is: /storage/external_SD.

Please note: When I use Environment.getExternalStorageDirectory().getPath() i get: /storage/emulated/0.
This is the path of the real internal storage card (the phone’s sd card) and not the real external storage card (the removable micro sd card).

我的问题是我可以写入“真正的内部存储卡”(手机的SD卡)但不能写入“真正的外部存储卡”(可移动微型SD卡).我需要在micro sd卡上保存文件.

我试过以下的事情:
FileOutputStream fos;
1)fos = new FileOutputStream(System.getenv(“SECONDARY_STORAGE”)“/ test.txt”);
2)fos = new FileOutputStream(“/ storage / external_SD / test.txt”);

在这两种方式中,我将micro SD卡的路径放在FileOutputStream的参数上,这样它就会将文件’test.txt’保存在micro sd卡上,但是我的应用程序崩溃了,没有任何反应!
另外,我也尝试创建一个文件夹,但它没有用.

但是,当我把手机的SD卡的路径,它的工作原理!
还有文件夹创建工作.

但我需要在micro sd卡上写文件.

在给我答案之前请注意以下事项:
1)我在清单中添加了以下权限:
    < uses-permission android:name =“android.permission.WRITE_EXTERNAL_STORAGE”/>
    < uses-permission android:name =“android.permission.READ_EXTERNAL_STORAGE”/>
2)在尝试应用程序之前,我曾尝试断开电缆与计算机的连接.
3)我尝试禁用调试模式.
4)我尝试了另一张micro sd卡.
5)我的智能手机是LG Optimus L7(LG P714).
6)我有Android KitKat(4.4.2).
7)当我在另一部智能手机(三星galaxy S3)上试用该应用程序时,当我在micro sd卡上保存文件时它仍然崩溃,但是当我保存文件夹时它成功了!

有谁知道这是什么问题?

解决方法:

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)

自四年前发布的Android 4.4以来就是这种情况.

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

您可以在Context上使用getExternalFilesDirs(),getExternalCacheDirs()和getExternalMediaDirs().请注意这些方法名称的复数形式.如果它们返回2个项目,则第二个和后续项目是可移动存储上的位置,对应用程序是唯一的,您可以读取和写入.

或者,使用Storage Access Framework并让用户选择放置内容的位置,使用生成的Uri和ContentResolver以及openOuptutStream()来写入该位置.这将允许用户使用外部存储,可移动存储以及第三方应用程序支持的位置(Google云端硬盘,SMB / CIFS文件服务器等).

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐