使用phonegap调用本机文件浏览器 [英] Invoke native file browser using phonegap

查看:194
本文介绍了使用phonegap调用本机文件浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在我的phonegap项目中实现文件上传功能。用户应该能够从手机内存或SD卡上传任何类型的文件。我使用jQuery Mobile框架设计的应用程序屏幕。我试过输入type =文件,但它不支持在Android 4.4。我也尝试过phonegap相机API,但它只支持媒体文件。我找到了一些cordova插件( exm1 exm2 )。但这些插件使用自定义UI。我想调用本机文件浏览器选择文件&它必须在Android& iPhone平台。

I have to implement file upload feature in my phonegap project. User should be able to upload any type of file from the phone memory or sd card. The application screens I designed using jQuery Mobile framework. I tried input type="file", but it is not supported in android 4.4. I tried phonegap camera API too, but it is supported only media files. I found some cordova plugins (exm1,exm2 ). But these plugins using custom UI. I want to invoke native file browser for choosing the file & it has to work in both Android & iPhone platforms. Is there a way to implement the same?

我发现cordova文件选择器插件( https://github.com/cdibened/filechooser )将有助于Android平台,但我无法使它的工作。成功回调函数不会立即被触发后的文件选择(测试与Android 4.4.2)。请在下面找到我的代码。

I found cordova file chooser plugin (https://github.com/cdibened/filechooser) would be helpful for android platform, but I am unable to make it work. The success callback function is not immediately getting triggered after the file selection (tested with android 4.4.2). Please find my code below,

< input type =fileid =fileinputname =fileinput/& code>

<input type="file" id="fileinput" name="fileinput"/>

$("#fileinput").bind('click',function(){ 
    console.log("choose file selected"); 
    filechooser.open( {}, fileChooseSuccess, fileChooseFailed ); 
}); 
function fileChooseSuccess(data) { 
    var filepath = data.filepath; 
    console.log("file path:"+filepath); 
} 
function fileChooseFailed(msg) { 
    console.log(msg); 
} 


推荐答案

插件,FileChooser工作。

I was able to get your plugin, FileChooser working.

有一些事情必须做。
您需要使用编辑器打开以下内容

There are certain things that have to be done though. You need to open the following with your editor


  • FileChooser.java

  • FileChooserActivity .java

  • FileListAdapter.java

  • FileListFragment.java

  • LocalStorageProvider.java

  • FileChooser.java
  • FileChooserActivity.java
  • FileListAdapter.java
  • FileListFragment.java
  • LocalStorageProvider.java

并附加

import your.package.name.R;

以下是我使用的演示代码:

Here is the demo code I used:

<html>
<head>
    <title>Hello World</title>
    <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">
    document.addEventListener("deviceready", function(){

        var success = function(data) {
            alert("File chosen: " + data.filepath); 
        };

        var error = function(msg) {
            console.log( msg );
        };

        $('#fileinput').click(function(e) {
            filechooser.open({}, success,error);
        });
     });
    </script>

</head>

<body>
     <input type="file" id="fileinput" name="fileinput"/>
</body>
</html>

另外,请注意,作者打算在KitKat 4.4.4中使用。它可以使用较低版本,但他不确定。

Also, be aware that the author intended this to be used in KitKat 4.4.4. It may work with lower versions but he's uncertain.

请注意,HTML5选择窗口与此选项之间的唯一区别是内部存储选项。

Take note that the only difference between the HTML5 choice window and this is the "Internal Storage" option.

希望这有助于。

这篇关于使用phonegap调用本机文件浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆