java – Android SD卡问题

我当前在开发APP和使用外部SD卡时遇到了一些问题.

>第一个问题是我检查是否安装了SD卡.即使没有插入SD卡,此函数也会返回true.我已经使用/尝试过以下代码:

> https://stackoverflow.com/a/12721994
> http://tsicilian.wordpress.com/2012/04/24/android-persistence-external-storage-sd-card/

来自developer.android.com

Every Android-compatible device supports a shared “external storage” that you can use to save files. This can be a removable storage media (such as an SD card) or an internal (non-removable) storage. Files saved to the external storage are world-readable and can be modified by the user when they enable USB mass storage to transfer files on a computer.

也许这是一个问题?

我正在使用LG L5(E610)

我已经为清单文件添加了正确的权限.

我的另一个问题可能与issue有关

很感谢任何形式的帮助.谢谢.

解决方法

你说:

The first problem is that I check if there is a SD card mounted. This function returns a true even if there is no SD card inserted.

我认为你偶然发现需要花费一些时间才能掌握的东西,因为它根本不是明确的.

在Android中你会发现2种内存:

>系统一,始终可用,高度安全:您的应用只能访问专用于您的一小部分,而其他应用无法在那里读取您的数据.
>共享的,通常称为公共,外部或“sdcard”.每个应用程序都具有对所有应用程序的读/写访问权限但它并不总是可用,因为你可以将它“挂载”在你的计算机上,具有在android中卸载它并因此隐藏它的效果. (但仅限于Android 3.X之前).

您将在野外找到3种设备:

>在某些设备上,此共享内存位于设备内部的芯片上.所以名称SD卡是不够的.但是,路径可能是“/ sdcard”
>在其他设备上,此共享内存位于您可以删除的真实SD卡上.
>在其他一些设备上,这个内存用于芯片上的一部分,另一部分用于SD卡上.

根据你的说法,我认为你是第三种设备.所以你的物理SD卡将在这种路径中找到:/ mnt / sdcard / external_sd /.遗憾的是,这是特定于设备的,我不认为Android API中有一些东西可以获得这条路径.

另外,请记住,自Android 3.X起,我们不再需要“挂载”这个共享内存了.所以你的共享内存将永远存在于Android,因为我们现在正在使用MTP协议.

这就是为什么isExternalStorageAvailable()返回true,即使你的sdcard被删除了.

以上是来客网为你收集整理的java – Android SD卡问题全部内容,希望文章能够帮你解决java – Android SD卡问题所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。