BingoTouch文件操作
☻FileReader对象
FileReader是W3C文件API的一部分,提供了四种方法异步加载File对象引用的文件的数据:
§ .readAsText(File f, [encoding]): 读取 File对象F并赋予一个字符串。 UTF-8编码是假设,但可以通过指定编码参数[encoding]设置一个不同的格式。
§ .readAsDataURL(File f):将File对象F读取为编码过的数据URL。
§ .readAsBinaryString(File f):将File对象F读取为一个二进制字符串。
§ .readAsArrayBuffer(File f): 将File对象F读取为一个 ArrayBuffer 对象。
来自 <http://article.yeeyan.org/view/286167/252343>
☻下载
//检查版本
$("#btnCheckVersion").tap(function(e){
//获取到当前应用标识
app.getInfo(function(appObj){
var appId=appObj.id;
//获取升级地址
app.setting.get("upgradeUrl","",function(checkUrl){
//checkUrl="http://developer.bingosoft.net:7080/bingo.touch.packager/bt/upgrade/bfa4402853c6426fb1e583d6ba6e51ff";
//发请求检查是否有新版本
var split = checkUrl.indexOf("?")!=-1?"&":"?" ;
app.progress.start("","正在检查更新...");
app.post(checkUrl+split+new Date().getTime() , {} , function(response){
if( typeof response=="object" && $.trim(response.returnValue) ){
var obj = eval( "("+$.trim(response.returnValue)+")" ) ;
app.progress.stop();
app.confirm("检测到有新版本:"+obj.versionCode+", 是否下载安装?",function(index){
if(index==1){
app.progress.start("","正在下载更新...");
if(window.devicePlatform=="android"){
var fileTransfer = new FileTransfer();
var uri = encodeURI(obj.upgradeUrl);
var fileName=appId+"_"+obj.versionCode+"."+uri.substr(uri.lastIndexOf('.')+1);
var filePath="/sdcard/download/"+fileName;
fileTransfer.download(
uri,
filePath,
function(entry) {
app.progress.stop();
app.hint("下载到:"+entry.fullPath);
console.log("download complete: " + entry.fullPath);
app.confirm("已经下载完成,是否立刻安装?",function(index){
if(index==1){
//安装指定文件
app.install(filePath);
}
});
},
function(error) {
app.progress.stop();
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
},
false,
{
headers: {
"Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
}
}
);
}else if(window.devicePlatform="iOS") {
//iOS的话就直接打开浏览器,地址是.plist
app.run(res.upgradeUrl,"");
}
}
});
}else{
app.progress.stop();
app.alert("已经是最新版本!");
}
},function(res){
app.alert(res.returnValue);
});
});
});
});
//退出应用
$("#btnExit").tap(function(e){
app.exit();
});
});

浙公网安备 33010602011771号