-4

I am creating a hybrid app using cordova version 6.3 . On Android, I would like to the user to select a file from their device. Basically, i want a file chooser to show up and then the user select a file that is store on the android phone.

The current input type="file" does not work. It did work with a different version of SDK(19) and cordova

Can you give me some hint or some some sample code showing how I can implement this feature

user2570135
  • 2,669
  • 6
  • 50
  • 80
  • there are lot of plugins available.. https://github.com/MaginSoft/MFileChooser / https://github.com/don/cordova-filechooser will work – Navneeth Oct 27 '16 at 12:31
  • The MfileChooser does not return a file and don/cordova-filechooser does not have an option to pick from the local android device... Did you get any of them to work? – user2570135 Oct 27 '16 at 15:59
  • Try this https://github.com/tigoe/BeginningNFC/tree/master/FileSender/plugins/com.megster.cordova.FileChooser Its working for me. – Navneeth Oct 28 '16 at 07:18
  • @Navneeth , I tried the plugins,it shows the chooser and files but it does not return the file .. I am using cordova 6.3, and sdk 23. What version did you use in your implementation – user2570135 Nov 11 '16 at 19:52

1 Answers1

1

The <input type="file"> element also doesn't work as you'd expect in iOS -- it displays a list of photos IIRC.

I ended up writing my own routine to iterate through the phone's directories (using the plugin cordova-plugin-file) and gather the files -- see https://stackoverflow.com/a/29905718/346550. After getting the list, I display the entries in an unordered list of hyperlinks. You could really display the file results however you wanted, though.

Community
  • 1
  • 1
eb1
  • 2,897
  • 3
  • 31
  • 42
  • I used the code in link but I do not see the files for download folder on android. How do you get this information . thanks – user2570135 Nov 11 '16 at 19:42
  • On the SD card, it's a subdirectory of `cordova.file.externalRootDirectory`. I'm not sure where it resides on the device itself (or if it's even accessible). That's probably another SO question. Here's some more details about the filesystem layouts -- they vary from platform to platform: https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/#file-system-layouts – eb1 Nov 14 '16 at 21:40
  • I should add: in Android > 5, you also need runtime permissions to see some files/directories. See https://stackoverflow.com/questions/47143656/no-fileentry-results-returned-on-android-6 – eb1 Jan 09 '18 at 19:51