PhoneGap的/科尔多瓦文件API。卸下卸载文件文件、科尔、多瓦、PhoneGap

2023-09-06 03:41:47 作者:戎马.

我要建一个的PhoneGap /科尔多瓦应用程序,下载一些文件,并保存在设备上。为此,我用的文件API。

I'm building a Phonegap/Cordova app that downloads some files and saves them on the device. For this I use the File API.

window.requestFileSystem(LocalFileSystem.PERSISTENT,
    0,
    function (fileSystem) {
        rootPath = fileSystem.root.fullPath;
    }, 
    fail
);

在iOS上,这将置 ROOTPATH​​ 的应用程序,这是很好的私有目录。在Android上,这将置 ROOTPATH​​ 到外部存储,这是一个有点问题,因为这些文件不依赖于应用程序,而不是删除根时,应用程序是删除。据我了解,在Android这样做的正确的方法是使用 getExternalFilesDir 。我怎样才能获得的 getExternalFilesDir 的功能,通过PhoneGap的?

On iOS this will set rootPath to the private directory of the app, which is good. On Android this will set rootPath to the root of the external storage, which is a bit of a problem since these files are not tied to the application and not removed when the App is deleted. As I understand it, the proper way of doing this on Android would be to use getExternalFilesDir. How can I get the functionality of getExternalFilesDir through Phonegap?

推荐答案

您会希望通过JS请求外部文件的目录。

You'd want to request the external files directory via JS.

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
    function (fileSystem) {
        fileSystem.root.getDirectory("Android/data/com.my.app/files", 
            {create: true, exclusive: false}, 
            function(dirEntry) {
                rootPath = dirEntry.fullPath;
            }, fail);;
    }, 
    fail
);

现在你有一个指向将被清理,当应用程序被卸载的区域的路径。

Now you have a path that points to an area that will be cleaned up when the app is uninstalled.