Calling your own file browser using phonegap

I need to implement the file upload function in my phonegap project. The user should be able to download files of any type from the phone or SD card. The screens of the applications that I developed using the jQuery Mobile platform. I tried input type = "file", but it is not supported in android 4.4. I also tried the camera API for phone calls, but it is only supported by media files. I found some cordova plugins ( exm1 , exm2 ). But these plugins use the user interface. I want to call my own file browser to select a file, and it should work on Android and iPhone platforms. Is there a way to implement the same?

I found the plugin to select the cordova file ( https://github.com/cdibened/filechooser ) will be useful for the Android platform, but I can not get it to work. The success callback function does not immediately start after selecting a file (verified using android 4.4.2). Please find my code below.

<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); } 
+8
jquery-mobile cordova cordova-plugins
source share
2 answers

I managed to connect your FileChooser plugin.

gskJM.png

There are certain things to do, though. You need to open in your editor

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

    and add

     import your.package.name.R; 

    for each of these 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, keep in mind that the author suggested that this would be used in KitKat 4.4.4. It may work with lower versions, but it is not sure.

Please note that the only difference is between the HTML5 selection window and the Internal Storage option.

Hope this helps.

+3
source share

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

the input file should also work on android (in most versions, but it doesn’t work on Android 4.4, 4.4.1 and 4.4.2) Inputting the HTML file in the Android web browser (android 4.4, kitkat)

there is no plugin for iOS, you do not have your own file browser.

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

0
source share

All Articles