下载文件卡住安卓应用程序:工作灯

Downloading files stuck android application: worklight

本文关键字:应用程序 工作 文件 下载      更新时间:2023-09-26

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

if(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)**
                                }   
                            }

函数下载文件夹(结果,数字视频品牌){

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);
}

}

从评论中,解决方案是:

在队列中下载文件,因为一次下载所有文件会导致 应用程序卡住...