文件下载

从网络上下载文档存在本地
牛刀小试
下载文件

android使用wps打开,ios内置打开容器,也可以用wps打开
打开文件
示例代码
//获取应用相关的目录,android和ios的目录结构不同
//android下可以存储在 /sdcard/download下面
//ios只能存储在应用里面
app.getAppDirectoryEntry(function(res){
    //区分平台,并将相应的目录保存到全局,方便下面下载的时候使用
    if(window.devicePlatform=="android"){
        window.savePath=res.sdcard;                     
    }else if(window.devicePlatform=="iOS"){
        window.savePath=res.documents;
    }
});

//下载文件
$("#btnDownloadFile").tap(function(){
    var fileTransfer=new FileTransfer();
    var uri=encodeURI("http://developer.bingosoft.net/bingotouch.docx");
    var filePath=window.savePath+"/bingotouch.docx";
    fileTransfer.download(
        uri,
        filePath,
        function(entry){
            app.hint("下载完成!");
            //将文件路径保存起来,方便后面调用
            window.fileUri=entry.fullPath;
            $("#downloadResult").html("path:"+entry.fullPath);
        },
        function(error){
            app.hint("下载失败");
            $("#downloadResult").html(JSON.stringify(error));
        }
    );
});

//用wps打开文件
$("#btnOpenFile").tap(function(){
    if(window.fileUri){
        var uri=encodeURI(window.fileUri);
        app.openFile(uri,"",function(res){
            app.hint("打开成功!");
        });
    }else{
        app.hint("请先下载文件");                 
    }
});