Cordova zip插件无法正常工作

时间:2016-01-19 09:01:03

标签: android cordova sdk zip unzip

我正在尝试使用cordova zip插件。我创建了一个简单的cordova项目,添加了android平台和plugins.Inside index.html,我有简单的代码如下:

<html>
    <head>
        <!--
        Customize this policy to fit your own app's needs. For more guidance, see:
            https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
        Some notes:
            * gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
            * https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
            * Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
                * Enable inline JS: add 'unsafe-inline' to default-src
        -->
        <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
        <link rel="stylesheet" type="text/css" href="css/index.css">
        <title>Zip Plugin to extract files</title>
    </head>
    <body>
        <div class="app">
            <h1>Zip Plugin to extract files</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received">Device is Ready</p>
            </div>
        </div>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>      
        <script type="text/javascript" src="js/index.js">
            document.addEventListener("deviceready", function(){
            $('#zipfile').click(function(e) {
                zip.unzip("https://drive.google.com/file/d/0B6zHrNsznc9BUXBVTUE0OE9vY0E/view?ts=569cbb1c", "http://www.google.com", 
                    function(){
                         console.log('Zip decompressed successfully');
                    }
                );
            });
        </script>
         <button type="file" id="zipfile" name="zipFile"/>
    </body>
</html>

问题:我无法调用click事件处理程序;我也对我为解压缩编写的代码持怀疑态度。如果我缺少任何强制方法以便使用zip插件,请告诉我。 我在Android-23 sdk(win7机器)中尝试最新的cordova版本。

非常感谢任何帮助。提前谢谢。

1 个答案:

答案 0 :(得分:2)

根据文档,解压缩的第二个参数是目标。您使用google.com作为目的地,这没有任何意义。您想要使用本地路径。