如何在安卓上使用FileTransfer.download

4

我在安卓上使用Phonegap 1.9.0,但网上的示例很少,所以我担心文件下载。

var ft = new FileTransfer();
ft.download(
    "http://www.something.com/test.zip",
    "test.zip", // <- Trouble 1
    function(entry) {
        alert("success");
    },
    function(err) {
        alert(err); // <- Trouble 2
    }
);

1.我不理解适合该参数的文件路径指定方式。我应该如何指定本地路径?还是需要Android.permission权限?
2.显示“未找到类”的消息。这是什么原因?
3.已下载文件在本机Java中的路径是什么?

3个回答

1
// This worked for me
var ft = new FileTransfer();
ft.download(
  "http://www.something.com/test.zip", // what u download
  "/sdcard/test.zip", // this is the filename as well complete url
  // fileSystem.root.toURL() + "test.zip",  use ios and others
  function(entry) {
    alert("success");
    alert(JSON.stringify(entry));

  },
  function(err) {
    alert(err);
    alert(JSON.stringify(err));
  }
);

你可以在ADT Eclipse DDMS透视图中检查目录结构 -> 文件资源管理器。

1
"com/test.zip",fileSystem.root.toURL() + "test.zip" - RouR

1

没错,Cordova/Phonegap文档中缺乏真实世界的例子!

  1. Simon Mac Donald在下载方面有一篇很棒的文章:http://simonmacdonald.blogspot.co.uk/2012/04/sorry-for-being-gone-so-long-vacation.html 如果你想要下载多个文件,请查看他的gist:https://gist.github.com/3835045

  2. 我认为FileTransfer只能在设备上使用(也许是模拟器?),但我在浏览器中也遇到了这个错误 - 也许其他人可以提供解释/解决方法。

  3. 这将取决于平台,但可以通过FileSystem.root.fullPath找到。如果你要添加文件名,需要加上斜杠。


0
var ft = new FileTransfer();
ft.download(
    "http://www.something.com/test.zip", // what u download
    "", // this is dir which u download, right now, it will download to mnt/sdcard/
    function(entry) {
        alert("success");
    },
    function(err) {
        alert(err); 
    }
);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接