Phonegap / Cordova API Delete files when deleting

I am creating a Phonegap / Cordova application 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 ); 

On iOS, this will install rootPath in the applicationโ€™s private directory, which is good. On Android, this will install rootPath in the root folder of the external storage, which is a problem because these files are not attached to the application and are not deleted when the application is deleted. As far as I understand, the correct way to do this on Android would be to use getExternalFilesDir . How can I get getExternalFilesDir functionality via Phonegap?

+4
source share
2 answers

You want to request a directory of external files through 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 pointing to the area that will be cleared when the application is uninstalled.

+4
source

You cannot track the delete event. but to remove the directory is the code below.

 function deleteDirectory(directoyName){ $scope.fs.root.getDirectory(directoyName,{ create: false, exclusive: false }, function(dirEntry) { dirEntry.removeRecursively(function() { console.log('Directory Successfully Removed.'); }, errorHandler); }, errorHandler); } 
0
source

All Articles