2016-09-19 181 views
0

mfilechooser插件适用于android模拟器或设备上基于cordova的应用程序。没有错误报告,但选择器未启动。科尔多瓦插件'mfilechooser'不适用于科尔多瓦的Android手机6.3.1

这是我的代码的片段。

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

感谢您的帮助

+0

添加此做你解决了该问题?我也面临同样的问题。任何建议。 – Ironic

+0

没有解决方案..不适用于SDK 23和cordova 6.3.1。我已经尝试了大部分推荐的插件,但我仍然卡住..目前,我正在使用此插件[http://github.com/don/cordova-filechooser.git]/然而,回调没有得到触发,但我可以看到文件弹出和Android系统上的文件 – user2570135

+0

我在奇怪的问题。我已经在config.xml中添加了插件cordova add plugin,但它并没有解雇。我没有得到文件选择对话框或任何东西。萤火虫也没有错误。 – Ironic

回答

0

您的CSP可能不允许您运行内嵌JavaScript,因此onclick没有做任何事情。

尝试在Content-Security-Policy meta标签

script-src 'unsafe-inline';