PhoneGap的/科尔多瓦文件API。卸下卸载文件 [英] Phonegap/Cordova file API. Remove files on uninstall

查看:173
本文介绍了PhoneGap的/科尔多瓦文件API。卸下卸载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建一个的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.

这篇关于PhoneGap的/科尔多瓦文件API。卸下卸载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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