我一直在尝试将时间戳和位置保存到一个文件中,我需要调用data.bin。我尝试跟随cordova plugin file site,但我没有成功。有没有人建议我能做什么?这是我的代码:
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<!-- <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1"> -->
<meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=no">
<!-- <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes, minimum-scale=1, maximum-scale=2"> -->
/* following three (cascaded) are equivalent to above three meta viewport statements */
/* see http://www.quirksmode.org/blog/archives/2014/05/html5_dev_conf.html */
/* see http://dev.w3.org/csswg/css-device-adapt/ */
@-ms-viewport { width: 100vw ; min-zoom: 100% ; zoom: 100% ; }
@viewport { width: 100vw ; min-zoom: 100% zoom: 100% ; }
@-ms-viewport { user-zoom: fixed ; min-zoom: 100% ; }
@viewport { user-zoom: fixed ; min-zoom: 100% ; }
/*@-ms-viewport { user-zoom: zoom ; min-zoom: 100% ; max-zoom: 200% ; } @viewport { user-zoom: zoom ; min-zoom: 100% ; max-zoom: 200% ; }*/
var todayDate = new Date();
var imgLocation = getLocaleName();
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
navigator.splashscreen.show();
setTimeout(function(){ navigator.splashscreen.hide(); }, 3000);
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
document.getElementById("getLocaleName").addEventListener("click", getLocaleName);
}
window.requestFileSystem(window.TEMPORARY, 5 * 1024 * 1024, function (fs) {
console.log('file system open: ' + fs.name);
createFile(fs.root, "newTempFile.txt", false);
}, onErrorLoadFs);
function createFile(dirEntry, fileName, isAppend) {
// Creates a new file or returns the file if it already exists.
dirEntry.getFile(fileName, {create: true, exclusive: false}, function(fileEntry) {
writeFile(fileEntry, null, isAppend);
}, onErrorCreateFile);
}
function writeFile(fileEntry, dataObj) {
// Create a FileWriter object for our FileEntry (log.txt).
fileEntry.createWriter(function (fileWriter) {
fileWriter.onwriteend = function() {
console.log("Successful file write...");
readFile(fileEntry);
};
fileWriter.onerror = function (e) {
console.log("Failed file write: " + e.toString());
};
// If data object is not passed in,
// create a new Blob instead.
if (!dataObj) {
dataObj = new Blob(['some file data'], { type: 'text/plain' });
}
fileWriter.write(dataObj);
});
}
function readFile(fileEntry) {
fileEntry.file(function (file) {
var reader = new FileReader();
reader.onloadend = function() {
console.log("Successful file read: " + this.result);
displayFileData(fileEntry.fullPath + ": " + this.result);
};
reader.readAsText(file);
}, onErrorReadFile);
}
window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function (dirEntry) {
console.log('file system open: ' + dirEntry.name);
var isAppend = true;
createFile(dirEntry, "fileToAppend.txt", isAppend);
}, onErrorLoadFs);
function writeFile(fileEntry, dataObj, isAppend) {
// Create a FileWriter object for our FileEntry (log.txt).
fileEntry.createWriter(function (fileWriter) {
fileWriter.onwriteend = function() {
console.log("Successful file write...");
if (dataObj.type == "image/png") {
readBinaryFile(fileEntry);
}
else {
readFile(fileEntry);
}
};
fileWriter.onerror = function(e) {
console.log("Failed file write: " + e.toString());
};
fileWriter.write(dataObj);
});
}
function readBinaryFile(fileEntry) {
fileEntry.file(function (file) {
var reader = new FileReader();
reader.onloadend = function() {
console.log("Successful file write: " + this.result);
displayFileData(fileEntry.fullPath + ": " + this.result);
var blob = new Blob([new Uint8Array(this.result)], { type: "image/png" });
displayImage(blob);
};
reader.readAsArrayBuffer(file);
}, onErrorReadFile);
}
function displayImage(blob) {
// Displays image if result is a valid DOM string for an image.
var elem = document.getElementById('imageFile');
// Note: Use window.URL.revokeObjectURL when finished with image.
elem.src = window.URL.createObjectURL(blob);
}
function displayImageByFileURL(fileEntry) {
var elem = document.getElementById('imageFile');
elem.src = fileEntry.toURL();
}
<div class="upage" id="mainpage">
<div class="upage-outer">
<div class="uib-header header-bg container-group inner-element uib_w_19" data-uib="layout/header" data-ver="0" id="headerMenu">
<h2>Main Menu</h2>
<div class="widget-container wrapping-col single-centered"></div>
<div class="widget-container content-area horiz-area wrapping-col left"></div>
<div class="widget-container content-area horiz-area wrapping-col right"></div>
</div>
<div class="upage-content ac0 content-area vertical-col left" id="page_87_98">
<div class="list-group widget uib_w_1 d-margins" data-uib="twitter%20bootstrap/list_group" data-ver="1">
<a class="list-group-item allow-badge widget uib_w_2" data-uib="twitter%20bootstrap/list_item" data-ver="1"><span class="badge"></span>
<p class="list-group-item-text list" onclick="takepicture()">Camera</p></a> <a class="list-group-item allow-badge widget uib_w_3" data-uib="twitter%20bootstrap/list_item" data-ver="1"><span class="badge"></span>
<p class="list-group-item-text list">Gallery</p></a> <a class="list-group-item allow-badge widget uib_w_4" data-uib="twitter%20bootstrap/list_item" data-ver="1"><span class="badge glyphicon glyphicon-briefcase"></span>
<p class="list-group-item-text list">Settings</p></a> <a class="list-group-item allow-badge widget uib_w_16 d-margins" data-uib="twitter%20bootstrap/list_item" data-ver="1">
<p class="list-group-item-text list" onclick="exitApplicationPressed()">Exit Application</p></a>
</div>
</div>
</div>
</div>
<div class="upage hidden" id="Settings">
<div class="upage-outer">
<div class="uib-header header-bg container-group inner-element uib_w_10" data-uib="layout/header" data-ver="0" id="headerSettings">
<h2>Settings</h2>
<div class="widget-container wrapping-col single-centered"></div>
<div class="widget-container content-area horiz-area wrapping-col left">
<button class="btn widget uib_w_11 d-margins btn-default" data-uib="twitter%20bootstrap/button" data-ver="1" id="Setting-Back">Back</button>
</div>
<div class="widget-container content-area horiz-area wrapping-col right"></div>
</div>
<div class="upage-content ac0 content-area vertical-col left" id="page_79_75">
<div class="list-group widget uib_w_12 d-margins" data-uib="twitter%20bootstrap/list_group" data-ver="1">
<a class="list-group-item allow-badge widget uib_w_13" data-uib="twitter%20bootstrap/list_item" data-ver="1">
<p class="list-group-item-text">Delete Stored Data</p></a> <a class="list-group-item allow-badge widget uib_w_14" data-uib="twitter%20bootstrap/list_item" data-ver="1">
<p class="list-group-item-text">Change Theme</p></a> <a class="list-group-item allow-badge widget uib_w_15" data-uib="twitter%20bootstrap/list_item" data-ver="1">
<h4 class="list-group-item-heading">Heading</h4>
<p class="list-group-item-text">List item</p></a>
</div>
</div>
</div>
</div>
<div class="upage hidden" id="gallery">
<div class="upage-outer">
<div class="uib-header header-bg container-group inner-element uib_w_8" data-uib="layout/header" data-ver="0" id="headerGallery">
<h2>Gallery</h2>
<div class="widget-container wrapping-col single-centered"></div>
<div class="widget-container content-area horiz-area wrapping-col left">
<button class="btn widget uib_w_7 d-margins btn-default" data-uib="twitter%20bootstrap/button" data-ver="1" id="Gallery-Back">back</button>
</div>
<div class="widget-container content-area horiz-area wrapping-col right">
<button class="btn widget uib_w_9 d-margins btn-default" data-uib="twitter%20bootstrap/button" data-ver="1">Camera</button>
</div>
</div><img id="smallImage" src="" style="display:none;width:60px;height:60px;">
<p id="time"></p>
<p id="local"></p>
<div class="upage-content ac0 content-area vertical-col left" id="page_80_76"></div><!-- div-->
</div>
</div>
<div class="upage hidden" id="Camera">
<div class="upage-outer">
<div class="uib-header header-bg container-group inner-element uib_w_26" data-uib="layout/header" data-ver="0">
<h2>Camera</h2>
<div class="widget-container wrapping-col single-centered"></div>
<div class="widget-container content-area horiz-area wrapping-col left">
<button class="btn widget uib_w_27 d-margins btn-default" data-uib="twitter%20bootstrap/button" data-ver="1" id="cBack">Back</button>
</div>
<div class="widget-container content-area horiz-area wrapping-col right"></div>
</div><button onclick="capturePhoto();">Capture Photo</button><br>
<button onclick="onSuccess();">Capture Editable Photo</button><br>
<button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
<button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From Photo Album</button><br>
<img id="largeImage" src="" style="display:none;">
<div class="upage-content ac0 content-area vertical-col left" id="page_71_45"></div>
</div>
</div>
<div class="upage hidden" id="Theme">
<div class="upage-outer">
<div class="uib-header header-bg container-group inner-element uib_w_28" data-uib="layout/header" data-ver="0" id="headerTheme">
<h2>Theme</h2>
<div class="widget-container wrapping-col single-centered"></div>
<div class="widget-container content-area horiz-area wrapping-col left">
<button class="btn widget uib_w_29 d-margins btn-default" data-uib="twitter%20bootstrap/button" data-ver="1" id="TBack">Back</button>
</div>
<div class="widget-container content-area horiz-area wrapping-col right"></div>
</div>
<div class="upage-content ac0 content-area vertical-col left" id="page_30_29">
<div class="list-group widget uib_w_30 d-margins" data-uib="twitter%20bootstrap/list_group" data-ver="1">
<a class="list-group-item allow-badge widget uib_w_31" data-uib="twitter%20bootstrap/list_item" data-ver="1">
<h4 class="list-group-item-heading" onclick="red()">Red theme</h4></a> <a class="list-group-item allow-badge widget uib_w_32" data-uib="twitter%20bootstrap/list_item" data-ver="1">
<h4 class="list-group-item-heading" onclick="blue()">Blue Theme</h4></a> <a class="list-group-item allow-badge widget uib_w_33" data-uib="twitter%20bootstrap/list_item" data-ver="1">
<h4 class="list-group-item-heading" onclick="green()">Green Theme</h4></a>
</div>
</div>
</div>
</div>