我能找到的与文件存储有关的最接近文档是 这篇文章(如果您无法访问它,请参见下文),但这给我留下了几个问题。
我真的,真的,真的很喜欢对什么路径映射到这里的存储进行专业的解释,看看我们应该如何对它们进行硬编码,以及我们期望如何精确地访问它们。实际的代码示例将是最棒的。我对此的最佳猜测是:
- /sdcard->映射到内部eMMC插槽,访问受到限制。
环境.getExternalStorageDirectory(); ...仍然返回这个。
- /媒体->映射到内部 8GB 内存(我可以写入这个)
- /data -> ?
- ? ->映射到可选的 microSD 卡
如果 /sdcard 映射到受限存储?
现在引用 Nook 开发者文档:
背景 NOOK有两种不同的分区方案
当今市场上的彩色设备,其中一种只有 250MB 的可用空间
/data 分区上的应用程序和一个具有 4GB 可用空间的应用程序
/data 分区上的应用程序。结果,势在必行
应用程序的设计和开发方式是为了
有效管理空间。未能这样做的应用程序将不会被
接受通过商店分发。
领域相关技术建议或解决方案,如果您
应用需要大量数据(包括但不限于
图像、音频或视频内容),您应该下载这些
运行时资源并将它们存储在更大的分区中
设备。如果您的应用程序要请求并存储超过
100MB的数据或资源您必须遵守以下规定
限制:
您的申请必须在描述中清晰明确地说明
前提是大量数据被使用/传递
应用。您必须将您的资源和数据写入适当的
分割。可以检测设备是否有放大/数据
分区如下:
StatFs stat = new StatFs("/data");
长字节可用 = (long)stat.getBlockSize() *(long)stat.getBlockCount();
长megAvailable = bytesAvailable / 1048576;
if (megAvailable > 1000){
...将您的资源写入/data
} 别的 {
...将您的资源写入/mnt/media ...
}
将数据写入应用程序的 /data 上的私有空间
FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_WORLD_READABLE);
您的应用程序不应假设
设备上是否存在 SD 卡,但您可以通过呼叫进行测试
至
Environment.getExternalStorageState();如果未找到 SD 卡,
您的应用程序必须正常退出并向用户发出通知
至于退出原因。
请记住,要访问 /media 分区,以及
您需要在清单中声明外部存储:
;
The closest thing to documentation I can find having to do with file storage is this post (see below if you can't access it), but it leaves me with several questions.
I would really, really, really like a knowledgeable explanation of what paths map to what storage here, seeing as how we're supposed to hard-code them, and how precisely we're expected to access them. An actual code sample would be superlative. My best guess from messing around with this is that:
- /sdcard-> maps to the internal eMMC slot, and access is restricted.
Environment.getExternalStorageDirectory(); ... still returns this.
- /media -> maps to the internal 8GB memory (I can write to this)
- /data -> ?
- ? -> maps to the optional microSD card
How can we access the external (optional, additional, the one you can pop out) sdcard, if /sdcard maps to restricted storage instead?
Now to quote the Nook developer docs:
Background There are two different partition schemes for the NOOK
Color devices in market today, one with only 250MB available to
applications on the /data partition and one with 4GB available to
applications on the /data partition. As a result, it is imperative
that applications are designed and developed in such a way as to
manage space effectively. Applications which fail to do so will not be
accepted for distribution via the Shop.
Area Associated Technical Recommendation or Solution if your
application requires large amount of data (including but not limited
to images, audio or video content), you should download those
resources at runtime and store them in the larger partition of the
device. If your application is going to request and store more than
100MB of data or resource you MUST abide by the the following
restrictions:
Your application must clearly and explicitly state in the description
provided that a large amount of data is used/delivered by the
application. You MUST write your resources and data onto appropriate
partition. You can detect if the device has an enlarged /data
partition as follows :
StatFs stat = new StatFs("/data");
long bytesAvailable = (long)stat.getBlockSize() *(long)stat.getBlockCount();
long megAvailable = bytesAvailable / 1048576;
if (megAvailable > 1000){
... write your resources in /data
} else {
... write your resources on /mnt/media ...
}
To write data into your application's private space on /data
FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_WORLD_READABLE);
Your application should NOT assume the
presence of an sdcard on device, but you can test for one via a call
to
Environment.getExternalStorageState(); If an SD Card is not found,
your application MUST exit gracefully with a notification to the user
as to the reason for the exit.
Remember, that to access the /media partition, as well as
ExternalStorage you need to declare in your manifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE">
</uses-permission>
发布评论
评论(2)
好的,这就是我过去几周学到的东西。
如果您想写入内部 SD 卡,请使用Context.getFilesDir()。它将返回您的应用程序的私有目录。您不能在内部闪存(也称为“/data”)上创建自己的目录。除了分配给您的应用程序的文件夹之外,您无权在任何地方进行写入。据说有两个内部分区,“/data”和“/media”,但我无法进入“/media”来挽救我的生命。
您可以使用外部闪存“/sdcard”(如果有)。这是您可以从设备中弹出的卡。有两种方法可以解决此问题:
当您的应用程序被卸载时)。您可以使用以下命令找到该文件夹
Context.getExternalFilesDir()。
Environment.getExternalStorageDirectory() /等等。
这篇文章,作者: B&N 代表(我在问题中提到)结果有点转移注意力,“/sdcard”没有映射到 eMMC 插槽,我不知道“我们将 SD 卡映射到内部 eMMC”是什么意思。
此 B&N post 说“/media”是内部的,但即使我有适当的清单权限,我也无法写入它......所以想想吧。
这是我的测试设备的屏幕截图,显示了可以访问和不可访问的内容:
代码(请注意,默认情况下,FileUtils 不包含在 sdk 中,它来自组织.apache.commons.io 库):
Okay, here's what I've learned in the past couple of weeks.
If you want to write to the internal SDcard, use Context.getFilesDir(). It'll return the private directory for your application. You can not invent your own directories on the internal flash storage (aka "/data"). You don't have permission to write anywhere other than the folder your application gets assigned. Supposedly there are two internal partitions, "/data" and "/media", but I can't get at "/media" to save my life.
You can use the external flash memory, "/sdcard", when one is available. This is the card you can pop out of the device. There are two ways to go about this:
when your application is uninstalled). You can find that folder with
Context.getExternalFilesDir().
Environment.getExternalStorageDirectory() / whatever.
This post by a B&N rep (which I referenced in my question) turned out to be a bit of a red herring, "/sdcard" doesn't map to the eMMC slot, and I have no idea what "we mapped the SD card to our internal eMMC" means.
This B&N post says that "/media" is internal, but I can't write to it even though I have the proper manifest permissions... so go figure.
This is a screencap of my test device, showing what is and isn't accessible:
The code for that (note that FileUtils isn't included in the sdk by default,it's from the org.apache.commons.io lib):
首先尝试以下方法:
如果这些都没有返回您可以写入的目录,请检查以下google-groups 线程,并使用上一个答案中提供的代码,它枚举所有当前挂载点:
如果可以在 Nook 设备运行时将 microSD 卡插入其中,您还可以尝试以下操作:
First of all try the following methods:
If neither of those return you a directory where you can write to, check the following google-groups thread, and use the code provided in the last answer, which enumerates all current mount-points:
If it is possible to insert the microSD card in the Nook device, while it is running, you could also try the following: