Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- document.addEventListener('deviceready',init,false);
- function init()
- {
- window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, fileSystemSuccess, fileSystemError);
- }
- function fileSystemSuccess(FileSystemObj)
- {
- AppCacheDir = "Android/data/com.mentable.android/cache";
- var fileSystemName = FileSystemObj.name;
- var fileSystemRoot = FileSystemObj.root;
- console.log("the file system name is "+fileSystemName);
- console.log('File system path is = '+fileSystemRoot.fullPath);
- fileSystemRoot.getDirectory(AppCacheDir, {create: true, exclusive: false}, gotDir, lostDir);
- }
- function fileSystemError()
- {
- console.log('access to file system failed');
- }
- function gotDir(DirEntry)
- {
- var entryReader = DirEntry.createReader();
- entryReader.readEntries(gotFilesInDir, lostFilesInDir);
- console.log('Am in the directory :)');
- var dir_full_path = DirEntry.fullPath;
- console.log("The Absolute path of this directoty is "+dir_full_path);
- var tartan_image = 'http://www.scotsconnection.com/uploads/images_products/1831.jpg';
- downloadFile(tartan_image,dir_full_path+'/lovely_tartan.jpg');
- var entryReader2 = DirEntry.createReader();
- entryReader2.readEntries(gotFilesInDir, lostFilesInDir);
- }
- function lostDir(ErrorObj)
- {
- console.log('lost access to dir '+ErrorObj.code);
- }
- function gotFilesInDir(DFileEntry)
- {
- console.log("There are "+DFileEntry.length+" files in this dir");
- for(var i = 0 ; i < DFileEntry.length; i++)
- {
- console.log('File name is '+DFileEntry[i].name);
- }
- }
- function lostFilesInDir()
- {
- console.log('Holy crap lost access to files in dir ):');
- }
- function downloadFile(url, target)
- {
- var fileTransferHandle = new FileTransfer();
- var source = encodeURI(url);
- fileTransferHandle.download(source, target, fileDownloaded, downloadFailed, false);
- }
- function fileDownloaded(downloadEntry)
- {
- console.log("Hey File download was successfull cheers. :)");
- }
- function downloadFailed()
- {
- console.log("Oh no file download was not successfull (>:<)");
- }
Add Comment
Please, Sign In to add comment