Android 外部 SD 卡访问
Android External SD Card Access
长期 iOS 开发人员,高级 Android 程序员(但没有我想象的那么高级..大声笑)..
试图了解 Android 设备存储选项。在我的 android 设备上,我有一个 14Gig SD 卡。
当我写代码的时候
String strDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS)+ File.separator + "MyFolder";
它被放置在内部设备的 "Documents folder" 中(使用文件管理器查看时)。
路径似乎是
storage/emulated/0
我的 SD 卡(根据文件管理器)是
storage/extSdCard
为什么Environment.getExternalStoragePublicDirectory给我一个内部卡的路径?
我错过了什么让我找到了将文件存储到外部卡的路径。我想我知道部分原因是 OS 4.1 中 SD 卡访问的变化,但不确定我遗漏了什么。
我通读了Environment.getExternalStorageDirectory does not return the path to the removable storage,但还是不太清楚。我的应用目前使用 getExternalStoragePublicDirectory 存储文件,但是我的用户要求他们可以选择将其存储在 SDCard 上吗?
Why does Environment.getExternalStoragePublicDirectory give me a path to my intneral card?
因为external storage is not removable storage. Neither of those are internal storage.
however my users are requesting they have the option of storing it on the SDCard instead?
在 Android 4.4+ 上,要么使用 the Storage Access Framework (to allow the user to choose a storage location, including removable storage, Drive/Dropbox/other cloud providers, etc.), or use getExternalFilesDirs()
on Context
。后一种方法 returns a File[]
— 如果数组中有 2 个以上的元素,除了第一个元素之外的所有元素都是您可以读取和写入的可移动存储上的位置。您不能写入 Android 4.4+.
设备上的可移动存储上的任意位置
长期 iOS 开发人员,高级 Android 程序员(但没有我想象的那么高级..大声笑)..
试图了解 Android 设备存储选项。在我的 android 设备上,我有一个 14Gig SD 卡。
当我写代码的时候
String strDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS)+ File.separator + "MyFolder";
它被放置在内部设备的 "Documents folder" 中(使用文件管理器查看时)。
路径似乎是
storage/emulated/0
我的 SD 卡(根据文件管理器)是
storage/extSdCard
为什么Environment.getExternalStoragePublicDirectory给我一个内部卡的路径?
我错过了什么让我找到了将文件存储到外部卡的路径。我想我知道部分原因是 OS 4.1 中 SD 卡访问的变化,但不确定我遗漏了什么。
我通读了Environment.getExternalStorageDirectory does not return the path to the removable storage,但还是不太清楚。我的应用目前使用 getExternalStoragePublicDirectory 存储文件,但是我的用户要求他们可以选择将其存储在 SDCard 上吗?
Why does Environment.getExternalStoragePublicDirectory give me a path to my intneral card?
因为external storage is not removable storage. Neither of those are internal storage.
however my users are requesting they have the option of storing it on the SDCard instead?
在 Android 4.4+ 上,要么使用 the Storage Access Framework (to allow the user to choose a storage location, including removable storage, Drive/Dropbox/other cloud providers, etc.), or use getExternalFilesDirs()
on Context
。后一种方法 returns a File[]
— 如果数组中有 2 个以上的元素,除了第一个元素之外的所有元素都是您可以读取和写入的可移动存储上的位置。您不能写入 Android 4.4+.