下载文件卡住Android应用程序:worklight

时间:2013-10-19 06:45:31

标签: javascript android ibm-mobilefirst

我在工作灯上实现了一个应用程序,我需要从服务器上下载文件,它在Iphone5上运行良好意味着文件下载顺利而不会卡住应用程序流程。但是当我在三星galaxy s2上运行应用程序时( V 4.1)并开始使用for循环下载文件我的应用程序卡住直到下载完成。但是当我只有一个文件要下载但是当计数超过3或4时,它的工作正常。

如果(networkInfo.networkConnectionType == 'WIFI'){

                                $(brandClassDis).addClass('ui-disabled'); // Disabling the Brand.
                                $(".lms_loadernew").css("display", "block");
                                var syncProgBar = "#syncProgressBar"+result[0].json.BrandID;
                                var syncProgLabel = "#syncLoadingLabel"+result[0].json.BrandID;
                                $(syncProgBar).progressbar({
                                    value: 0,
                                }).show();
                                $(syncProgLabel).text(parseInt(0, 10)+"%").show();
                                localStorage.setItem("download"+result[0].json.BrandID,0);
                                localStorage.setItem("downloadSucc"+result[0].json.BrandID,0);
                                for(var i=0; i<result.length; i++){
                                    var obj = {VideoID:result[i].json.VideoID,BrandID:result[i].json.BrandID,CourseID:result[i].json.CourseID,LoadingStatus:"0"};
                                    VideosList.add(obj,{push:false});
                                    result[i].json.IsDownload = 2;
                                    Videos.replace(result);

                                            **downloadFolder(result[i],result.length)**

                                }   
                            }

function downloadFolder(result,numVideoBrand){

try{
    var loaderPer = 0;
    var courseId ="#sync_"+result.json.CourseID.replace(/ /g,'');
    var courseLabelId ="#loadingLabel"+result.json.CourseID.replace(/ /g,'');
    var syncProgBar = "#syncProgressBar"+result.json.BrandID.replace(/ /g,'');
    var syncProgLabel = "#syncLoadingLabel"+result.json.BrandID.replace(/ /g,'');
    var serverLoc = encodeURI(result.json.DownloadName);
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
        fileSystem.root.getDirectory("LMS_APP", {create: true, exclusive: false}, function(directory){
            var localPath = directory.fullPath+"/"+"Videos"+"/"+zipFileName;
            var ft = new FileTransfer();
            ft.download(serverLoc,localPath, function(entry) {
                entry.file(function(file) {
                    WL.Logger.debug("File size: " + file.size);
                    if(file.size<=854){
                        downloadFail("",result,numVideoBrand);
                        entry.remove(successRemove, failRemove);
                    }else{
                        if(localStorage.getItem("download"+result.json.BrandID) == null || localStorage.getItem("download"+result.json.BrandID) =="" || localStorage.getItem("download"+result.json.BrandID) == undefined){
                            localStorage.setItem("download"+result.json.BrandID,1);
                        }else{
                            localStorage.setItem("download"+result.json.BrandID,(localStorage.getItem("download"+result.json.BrandID)-(-1)));
                        }

                        localStorage.setItem("downloadSucc"+result.json.BrandID,(localStorage.getItem("downloadSucc"+result.json.BrandID)-(-1)));

                        WL.Logger.debug("Folder is:---->"+directory.fullPath+"/"+zipFileName);
                        WL.Logger.debug("download"+localStorage.getItem("download"+result.json.BrandID)+"..."+numVideoBrand+"........"+ localStorage.getItem("downloadSucc"+result.json.BrandID));
                        var loadedVideoPer = (( localStorage.getItem("download"+result.json.BrandID)/numVideoBrand)* 100);
                        $(syncProgBar).progressbar({
                            value: loadedVideoPer,
                        });
                        $(syncProgLabel).text(parseInt(loadedVideoPer, 10)+"%");
                        $(courseId).hide();
                        $(courseLabelId).hide();
                    }
                }, function(error){downloadFail(error,result,numVideoBrand);});

            }, function(error) {

            });
            $(courseId).progressbar({
                value: loaderPer,
            }).show();

            $(courseLabelId).text(parseInt(loaderPer, 10)+"%").show();

            ft.onprogress = function(progressEvent) {

                if (progressEvent.lengthComputable) {
                    loaderPer = ((progressEvent.loaded / progressEvent.total)*100);
                    $(courseId).progressbar({
                        value: loaderPer,
                    });
                    $(courseLabelId).text(parseInt(loaderPer, 10)+"%");
                    //courseLabelId.text(parseInt(loaderPer, 10) + "%" );
                    loadingStatus(result);
                } 
            };  

        },function(error){
            downloadFail(error,result,numVideoBrand);
        });

    }, function(error){
        downloadFail(error,result,numVideoBrand);
    });
}catch(e){

    WL.Logger.debug("exp in downloadFile: "+e);
    //alert("exp "+videoLoader);
}

}

1 个答案:

答案 0 :(得分:0)

从评论中,解决方案是:

  

下载队列中的文件,coz立即下载所有文件导致   申请卡住......