我正在开发一个需要从我的网站下载图片并将其存储在手机上的应用程序,但当我尝试使用phonegap时,它会显示可能出现的所有错误。我该怎么做才能纠正这个问题 =/ ?
(注:phonegap是一款跨平台移动应用程序开发框架)
var fileTransfer = new FileTransfer();
fileTransfer.download(
"http://developer.android.com/assets/images/home/ics-android.png",
"/",
function(entry) {
alert("download complete: " + entry.fullPath);
},
function(error) {
alert("download error source " + error.source);
alert("download error target " + error.target);
alert("upload error code" + error.code);
});
显示的错误信息是:
Download error source " the url used"
download error target: " the target used "
upload error code 1
我使用的是cordova 2.2.0版本。
以下是logcat错误日志:
12-06 09:07:26.413: E/FileTransfer(2186): {"target":"\/","source":"http:\/\/developer.android.com\/assets\/images\/home\/ics-android.png","code":1}
12-06 09:07:26.413: E/FileTransfer(2186): java.io.FileNotFoundException
12-06 09:07:26.413: E/FileTransfer(2186): at org.apache.cordova.FileTransfer.getFileFromPath(FileTransfer.java:794)
12-06 09:07:26.413: E/FileTransfer(2186): at org.apache.cordova.FileTransfer.access$700(FileTransfer.java:62)
12-06 09:07:26.413: E/FileTransfer(2186): at org.apache.cordova.FileTransfer$4.run(FileTransfer.java:631)
12-06 09:07:26.413: E/FileTransfer(2186): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
12-06 09:07:26.413: E/FileTransfer(2186): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
12-06 09:07:26.413: E/FileTransfer(2186): at java.lang.Thread.run(Thread.java:856)
genymotion android emulator
上测试,我的路径是file://storage/emulated/0/Download/nn.txt
。这可能是一个权限问题吗?另外,如何请求在/
位置保存的权限? - coding_idiot