我写了一个phonegap应用程序,我将在android图库中选择的文件复制到sd卡上。这个函数可以工作,但是会在拷贝时冻结主线程。
现在我测试了在Web Worker中编写这个,我将fileEntry发布到Web Worker,但是出现了一个错误:
03-18 09:31:37.575 1713-1713/de.scisys.app I/chromium﹕ [INFO:CONSOLE(1)] "Uncaught TypeError: Object #<Object> has no method 'copyTo'", source: blob:file%3A///7fd968c1-2d2b-469e-b4b7-fab1172bb496 (1)
下面是我的代码:
function(fileEntry) {
...
var blob = new Blob(['onmessage = function(e) { var data = e.data; data.fileEntry.copyTo(data.parentEntry, data.newName, function() { postMessage("success") }, function() { postMessage("error") }); }'], {type: 'text/javascript'});
var blobURL = window.URL.createObjectURL(blob);
var worker = new Worker(blobURL);
worker.onmessage = function(e) {
alert(e.data)
};
worker.postMessage({'fileEntry': fileEntry, 'parentEntry': parentEntry, 'newName': fileId+"."+fileName[fileName.length-1]});
...
}
是有一个错误在我的代码,或有一些人的想法?
谢谢你的帮助!
编辑: 我通过编辑Phonegap核心文件插件找到了一个解决方案。在FileUtils的"执行"方法中,我将工作更改为线程。http://www.mindfiresolutions.com/implementing多线程- - android -插件的phonegap - 260 - 2572. - php
据我所知,Web Workers从来不在本地目录下工作
文件://
它在服务器端工作。例如,与其将文件放在"file://"处,不如将路径设置为
***> http://locahost/ or***
***> http://server_ip_address***
因此Phonegap由位于设备目录下的HTML和Javascript组成,因此在Phonegap中不支持web worker。^^是我在谷歌上搜到的:)。请先google一下