【问题标题】:The cordova plugin 'mfilechooser'' is not working on Android phone with cordova 6.3.1科尔多瓦插件“mfilechooser”不适用于带有科尔多瓦 6.3.1 的 Android 手机
【发布时间】:2017-01-27 12:32:58
【问题描述】:

mfilechooser 插件适用于我在 android 模拟器或设备上的基于 cordova 的应用程序。未报告错误,但选择器未启动。

这是我的代码的 sn-p。

index.js

 function choose(){

    window.plugins.mfilechooser.open([], function (uri) {

      alert(uri);

    }, function (error) {

        alert(error);

    });
    }
    function onDeviceReady() { 
    }

    function domLoaded(){
      document.addEventListener("deviceready", onDeviceReady, false);

    }

index.html

<!DOCTYPE html>
    <html>
    <head>

        <meta http-equiv="Content-Security-Policy" 
            default-src 'self';
            connect-src *;
            style-src 'self' data: chrome-extension-resource:      'unsafe-inline';
            img-src 'self' data: chrome-extension-resource:;
            frame-src 'self' data: chrome-extension-resource:;
            font-src 'self' data: chrome-extension-resource:;
            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">
        <title>Hello World</title>
    </head>
    <body onload="domLoaded()">
        <div>
            <h1>Apache Cordova</h1>
        </div>
        <div>

             <button onClick="choose()">choose file</button>
        </div>

        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
    </body>
    </html>

科尔多瓦 6.3.1 文件选择器:https://github.com/MaginSoft/MFileChooser

感谢您的帮助

【问题讨论】:

  • 您解决了这个问题吗?我也面临同样的问题。任何建议。
  • 无解决方案.. 不适用于 SDK 23 和 cordova 6.3.1。我已经尝试了大部分推荐的插件,但我仍然卡住了.. 目前,我正在使用这个插件[github.com/don/cordova-filechooser.git] 但是,回调没有被触发,但我可以看到文件弹出和 android 系统上的文件
  • 我遇到了奇怪的问题。我已经在 config.xml 中添加了插件,也添加了cordova插件,但它没有触发。我没有得到文件选择对话框或任何东西。 firebug 也没有错误。
  • 我知道...尝试我之前评论中的另一个插件...您是从浏览器还是从设备/模拟器调用它
  • 我正在设备中测试它以及浏览器上的基本脚本相关问题/错别字测试。我尝试了两个插件,但都不是弹出文件系统。让我再试试。

标签: android cordova cordova-plugins filechooser


【解决方案1】:

您的 CSP 可能不允许您运行内联 javascript,因此 onclick 没有执行任何操作。

尝试将其添加到您的 Content-Security-Policy 元标记中

script-src 'unsafe-inline';

【讨论】:

    猜你喜欢
    • 2016-08-30
    • 1970-01-01
    • 2015-05-19
    • 1970-01-01
    • 2015-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多