LocalFileSystem.PERSISTENT 指向哪里? [英] Where does LocalFileSystem.PERSISTENT point to?

查看:37
本文介绍了LocalFileSystem.PERSISTENT 指向哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 PhoneGap 中,我使用

In PhoneGap, I use

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

访问文件系统.
在我的华硕平板电脑中,它没有external sdcard(我没有插入任何可移动设备)所以我认为文件系统根目录指向internal sdcard.然而,在我的 HTC Desire HD 中,数据被写入external sdcard.(因为数据只存在于 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:两个安卓版本都是ICS(冰淇淋三明治).

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

推荐答案

PhoneGap 的 FileAPI 虽然旨在反映 HTML5 规范,但实际上是 W3C 文档的自定义实现.您可以在此处找到特定于其 API 的文档.使用相同的方式,在 Web 和每个设备上的实现方式之间存在一些细微的差异.存储位置就是其中之一.

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 如何处理持久存储,我必须深入研究 Cordova 源代码.此处的此文件包含 PhoneGap FileAPI 使用的方法. 相关代码块从第 871 行开始.基本上,API 将调用 Environment.getExternalStorageState().如果返回 Environment.MEDIA_MOUNTED,则意味着存在 可移动或不可移动SD卡用于存储,API返回的FileSystem是挂载存储的根目录,使用Environment.getExternalStorageDirectory().这解释了您在具有内部和外部 SD 卡的设备之间看到的行为差异,两者都被系统视为已安装的外部存储.如果遇到没有任何外部存储的设备,即!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED),返回的文件系统的根将是内部存储,类似于调用Context.getFilesDir(),通常返回类似data/data/packageName/files"的内容.

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".

这篇关于LocalFileSystem.PERSISTENT 指向哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆