哪里LocalFileSystem.PERSISTENT点?LocalFileSystem、PERSISTENT

2023-09-04 05:39:12 作者:月亮邮递员

在PhoneGap的,我用

In PhoneGap, I use

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail);

要访问文件系统。 在我的华硕平板,它没有外接SD卡(我不会将任何可移动设备),所以我觉得在文件系统根目录指向内部SD卡。然而,在我的HTC Desire HD,数据被写入外接SD卡。 (因为数据只存在于microSD卡。) 那么,什么是真相?我看不出任何端倪的W3C文件中,也许我错过了什么......

to access the file system. In my ASUS tablet, it has no external sdcard(I don't insert any removable device) so I think the file system root points to the internal sdcard. However, in my HTC Desire HD, the data was written to the external sdcard. (Since the data just reside in the microSD card.) So what is the truth? I can't see any clues in the W3C document, maybe I miss something...

PS:无论是Android版本的ICS(冰淇淋三明治)

PS: Both the android version are ICS(Ice cream sandwich).

推荐答案

的PhoneGap的FileAPI,而旨在反映HTML5规范,实际上是一个自定义实现W3C文档。 你可以找到具体的在这里他们的API的文档。的虽然大多可以用同样的,有些事情是如何在网络上和每个设备实现之间有一些细微的差别。存储的位置是其中之一。

PhoneGap's FileAPI, while designed to mirror the HTML5 spec, is actually a custom implementation of the W3C document. You can find the docs specific to their API here. While it mostly can be used the same, there are some subtle differences between how things are implemented on the web and per device. The location of storage is one of these.

要找出的PhoneGap如何处理持久化存储,我不得不深入到科尔多瓦源$ C ​​$ C。 This此文件包含由该PhoneGap的FileAPI的方法。中的code中的相关块开始于行871基本上,API将调用 Environment.getExternalStorageState()。如果返回 Environment.MEDIA_MOUNTED ,这意味着要么一个的可移动或不可移动的SD卡进行存储,通过API返回的文件系统安装的存储的根目录下,使用 Environment.getExternalStorageDirectory()。这说明你看到的内部和外部SD卡的设备之间的行为差​​异,既考虑了系统安装的外部存储。如果你遇到一个设备,而无需任何外部存储器,即!Environment.getExternalStorageState()。等于(Environment.MEDIA_MOUNTED),返回的文件系统的根将是数据/数据/软件包名在内部存储,类似于呼叫 Context.getFilesDir(),通常会返回类似数据/数据​​/的packageName /文件。

To find out how PhoneGap handles persistent storage, I had to dig into the Cordova source code. This file here contains the methods used by the PhoneGap FileAPI. The relevant block of code starts at line 871. Basically, the API will make a call to Environment.getExternalStorageState(). If this returns Environment.MEDIA_MOUNTED, meaning there's either an removable or non-removable SD card for storage, the FileSystem returned by the API is the root directory of the mounted storage, using Environment.getExternalStorageDirectory(). This explains the difference in behavior you saw between devices with internal and external SD cards, both considered mounted external storage by the system. If you encounter a device without any external storage, i.e. !Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED), the root of the returned FileSystem will be "data/data/packageName" in internal storage, similar to calling Context.getFilesDir(), which usually returns something like "data/data/packageName/files".