Invoke native file browser using phonegap

前端 未结 2 1692
面向向阳花
面向向阳花 2021-01-02 14:59

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 de

相关标签:
2条回答
  • 2021-01-02 15:27

    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

      and append

      import your.package.name.R;
      

      to each of those files.

    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>
    

    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.

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

    Hope this helps.

    0 讨论(0)
  • 2021-01-02 15:31

    For android you can use this plugin: https://github.com/cdibened/filechooser

    input file should work on android too (on most of the versions, but it doesn't work on android 4.4, 4.4.1 and 4.4.2) HTML file input in android webview (android 4.4, kitkat)

    for iOS there is no plugin, you don't have a native file browser.

    Sample project https://github.com/jcesarmobile/FileBrowserAndroidTest

    0 讨论(0)
提交回复
热议问题