Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does LocalFileSystem.PERSISTENT point to?

In PhoneGap, I use

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

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: Both the android version are ICS(Ice cream sandwich).

like image 298
Alston Avatar asked May 06 '13 13:05

Alston


1 Answers

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.

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

like image 176
MattDavis Avatar answered Oct 14 '22 12:10

MattDavis