下载到本地存储android phonegap 3.4.0



我有下面的代码下载jpg到我的本地存储,但我没有得到任何文件下载我已经安装了以下插件

  • cordova plugin add org.apache.cordova.file-transfer
  • cordova plugin add org.apache.cordova.file

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <title>Hello World</title>
    </head>
      <body>
    <script type="text/javascript" src="cordova.js"></script>
    
    <script type="text/javascript" src="painlessfs.js"></script>
    <script type="text/javascript">
    var url = 'http://2d-code.co.uk/images/google-qr-code.jpg';
    var filePath = 'file:///android_asset/www/res/db/"';
    var fileTransfer = new FileTransfer();
    var uri = encodeURI(url);
    fileTransfer.download(
        uri,
        filePath,
        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);
        },
        false,
        {
            headers: {
                "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
            }
        }
    );
    </script>
    

在此之后,我运行了phonegap build android并在我的设备上安装了我的apk,但没有收到任何警报。

当deviceReadyevent触发时必须运行代码:

document.addEventListener("deviceReady", deviceReady, false);
function deviceReady() {
        //Your code goes here
}

应该是这样的:

document.addEventListener("deviceReady", deviceReady, false);
function deviceReady() {
    var url = 'http://2d-code.co.uk/images/google-qr-code.jpg';
    var filePath = 'file:///android_asset/www/res/db/"';
    var fileTransfer = new FileTransfer();
    var uri = encodeURI(url);
    fileTransfer.download(
        uri,
        filePath,
        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);
        },
        false,
        {
            headers: {
                "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
            }
        }
    );
}

阅读更多关于它

相关内容

  • 没有找到相关文章

最新更新