My friend. While i was waiting for your response i found a way to save archieves in my mobile device, i just have one problem now, with, i think, need a little more experience with javascript.
follow the code that i found:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
requestFileSystem(LocalFileSystem.PERSISTENT, 0, onSuccess, onError);
}
function onSuccess(fileSystem) {
alert(fileSystem);
var directoryEntry = fileSystem.root;
//lets create a file named readme.txt. getFile method actually creates a file and returns a pointer(FileEntry) if it doesn't exist otherwise just returns a pointer to it. It returns the file pointer as callback parameter.
directoryEntry.getFile("readme.txt", { create: true, exclusive: false }, function (fileEntry) {
//lets write something into the file
fileEntry.createWriter(function (writer) {
alert("This is the text inside readme file");
}, function (error) {
alert("Error occurred while writing to file. Error code is: " + error.code);
});
}, function (error) {
alert("Error occurred while getting a pointer to file. Error code is: " + error.code);
});
}
function onError(evt) {
alert("Error occurred during request to file system pointer. Error code is: " + evt.code);
}
This is simple and save a text Archive in my mobile device. I tried to use another code to create my csv arch, follow bellow:
$scope.criaCSV = function () {
// Create Object
var items = [
{ name: "Item 1", color: "Green", size: "X-Large" },
{ name: "Item 2", color: "Green", size: "X-Large" },
{ name: "Item 3", color: "Green", size: "X-Large" }];
// Convert Object to JSON
var jsonObject = JSON.stringify(items);
// Convert JSON to CSV & Display CSV
ConvertToCSV(jsonObject);
};
function ConvertToCSV(objArray) {
var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
var str = '';
for (var i = 0; i < array.length; i++) {
var line = '';
for (var index in array[i]) {
if (line != '') line += ','
line += array[i][index];
}
str += line + '\r\n';
}
return str;
}
The code above create my csv archive, but a ain’t able to pass that archive from the first code, making it saved in my mobile.
If you or anyone could help me, i again would be very grateful. Thank you again.