8

I created a web application that I need to convert to a mobile application, now all I have is html5/js/css files which means I don't have any www foder no platforms folder, not a cordova project ... I started first to build the app using cordova command lines, but I couldn't, I found many problems on that, I used then https://build.phonegap.com/ , and it works fine for me. In order to read the file, I have tried this code :

    window.resolveLocalFileSystemURI("file:///android_asset/www/data/User.xml", function () {
        alert("Success");
    }, function () {
        alert(" error ");
    });

but, it didn't work. I added a try catch, the exception was :

window.resolveLocalFileSystemURI is not a function

Do i need to add something to my code to make it work ?

Khalid
  • 4,730
  • 5
  • 27
  • 50

1 Answers1

10

You need to install a plugin for this to work.

Basically, run "cordova plugin add org.apache.cordova.file" at your application's root directory.

For detailed instructions see here, under "Accessing the Feature": http://docs.phonegap.com/en/edge/cordova_file_file.md.html#LocalFileSystem

UPDATE 2019

The correct way to add this plugin is now with this command in your project root:

cordova plugin add cordova-plugin-file

This is a core cordova plugin. Documentation found here on npm

Devin Carpenter
  • 907
  • 8
  • 21
Assaf Hershko
  • 1,846
  • 4
  • 18
  • 20
  • 1
    That seems to be outdated now. Check https://github.com/apache/cordova-plugin-file you need to use cordova plugin add cordova-plugin-file – Gaurav Ojha Nov 02 '16 at 05:08
  • 1
    I re-installed the plugin and my code started working on ios. Wasted a couple hours adding logging and all of the logging wouldn't even indicate that the plugin wasn't installed. Only that a function was undefined or whatever. Errors are vague :( – Quintonn Jul 28 '19 at 11:05