[英]Phonegap/Cordova file API. Remove files on uninstall
我正在構建一個Phonegap / Cordova應用程序,可以下載一些文件並將其保存在設備上。 為此,我使用File API。
window.requestFileSystem(LocalFileSystem.PERSISTENT,
0,
function (fileSystem) {
rootPath = fileSystem.root.fullPath;
},
fail
);
在iOS上,這會將rootPath
設置為應用程序的私有目錄,這很好。 在Android上,這會將rootPath
設置為外部存儲的根目錄,這有點問題,因為這些文件沒有綁定到應用程序,並且在刪除應用程序時不會刪除。 據我了解,在Android上執行此操作的正確方法是使用getExternalFilesDir
。 如何通過Phonegap獲取getExternalFilesDir
的功能?
您想通過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
);
現在,您有一條路徑指向卸載應用程序時將清理的區域。
你無法跟蹤卸載事件。 但要刪除目錄,代碼如下。
function deleteDirectory(directoyName){
$scope.fs.root.getDirectory(directoyName,{ create: false, exclusive: false }, function(dirEntry) {
dirEntry.removeRecursively(function() {
console.log('Directory Successfully Removed.');
}, errorHandler);
}, errorHandler);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.