0
votes

PhoneGap 3.3 file plugin not working with me on Android, i tried getFile and getDirectory, and keep giving me Exception

02-20 12:24:34.997: W/System.err(32109): java.net.MalformedURLException: No installed handlers for this URL
02-20 12:24:34.997: W/System.err(32109):    at org.apache.cordova.file.FileUtils.getFile(FileUtils.java:684)
02-20 12:24:35.007: W/System.err(32109):    at org.apache.cordova.file.FileUtils.access$5(FileUtils.java:679)
02-20 12:24:35.007: W/System.err(32109):    at org.apache.cordova.file.FileUtils$16.run(FileUtils.java:349)
02-20 12:24:35.017: W/System.err(32109):    at org.apache.cordova.file.FileUtils$24.run(FileUtils.java:473)
02-20 12:24:35.017: W/System.err(32109):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-20 12:24:35.017: W/System.err(32109):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-20 12:24:35.017: W/System.err(32109):    at java.lang.Thread.run(Thread.java:841)

JavaScript Code

downloadAgendaPage = function () {
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}

function gotFS(fileSystem) {
    console.log("Emaish: FileSystem Requested");
    console.log("Emaish: fileStream.name = " + fileSystem.name);
    console.log("Emaish: fileStream.root.name = " + fileSystem.root.name);
    fileSystem.root.getFile("text.txt", {create: true, exclusive: false}, gotFileEntry, fail);
}

function gotFileEntry(fileEntry) {
    console.log("Emaish: File Gotten");
    var uri = encodeURI("http://****/data/MYOEB2013_Agenda.ics");
    console.log("Emaish: uri:" + uri);
    var sPath = fileEntry.fullPath.replace("text.txt", "Agenda.ics");
    console.log("Emaish: sPath:" + sPath);
    fileEntry.remove();
    var fileTransfer = new FileTransfer();
    fileTransfer.download(
        uri,
        sPath,
        function (theFile) {
            console.log("download complete: " + theFile.toURI());
            //showLink(theFile.toURI());
            alertify.alert("Agenda downloaded to " + theFile.toURI());
        },
        function (error) {
            console.log("download error source " + error.source);
            console.log("download error target " + error.target);
            console.log("upload error code: " + error.code);
        }
    );
}

Console.log Result

02-20 16:15:37.205: I/chromium(23491): [INFO:CONSOLE(59)] "Emaish: FileSystem Requested", source: file:///android_asset/www/js/agenda.js (59)
02-20 16:15:37.205: I/chromium(23491): [INFO:CONSOLE(60)] "Emaish: fileStream.name = persistent", source: file:///android_asset/www/js/agenda.js (60)
02-20 16:15:37.205: I/chromium(23491): [INFO:CONSOLE(61)] "Emaish: fileStream.root.name = ", source: file:///android_asset/www/js/agenda.js (61)
2
Can you provide more information please? What are you passing in as a parmater?keldar
i updated the question to show the javascript CodeAbou-Emish
Log Result 02-20 16:15:37.205: I/chromium(23491): [INFO:CONSOLE(59)] "Emaish: FileSystem Requested", source: file:///android_asset/www/js/agenda.js (59) 02-20 16:15:37.205: I/chromium(23491): [INFO:CONSOLE(60)] "Emaish: fileStream.name = persistent", source: file:///android_asset/www/js/agenda.js (60) 02-20 16:15:37.205: I/chromium(23491): [INFO:CONSOLE(61)] "Emaish: fileStream.root.name = ", source: file:///android_asset/www/js/agenda.js (61)Abou-Emish
Hmm odd - seems sane. I would recommend opening org.apache.cordova.file.FileUtils and debugging the line it says it crashes on. At least that way you can tell which path it's trying to resolve, and possibly why the error is happening.keldar
values are: baseURLstr = "/" , path = "text.txt" after executing inputURL = new LocalFilesystemURL(baseURLstr); the result: inputURL.filesystemName is null and also inputURL.fullPath is nullAbou-Emish

2 Answers

1
votes

The reason for this strange error is that i was manually updating the cordova-plugins.js file and manually adding the plugins js files, because they were n't added automatically. Why they weren't added automatically? because i was doing it wrong ..

The Answer is don't build then add the plugins, instead add the plugin then build then replace www files with yours.

0
votes

There is a change in reading the directory structure in phonegap 3.3.0.

I was facing a similar issue where i have to read all the files inside a directory by using fullPath with window.resolveLocalFileSystemURL().

I tried using fileEnteries.fullPath for getting absolute path, but it dint work it was showing '/'(root) as earlier version it used to be 'file:///'.

*Use entries[i].toURL() to get absoulte path rather than fileEnteries.fullPath *

    for (var i = 0; i < entries.length; i++) {

        //Adding into Store for my example          
        data.push({
            fileName : entries[i].name,
            isDirectory : entries[i].isDirectory,
            fullPath : entries[i].toURL() //instead of entries[i].fullPath
        });
    }

and later use in window.resolveLocalFileSystemURL(entries[i].toURL() ,success,failuere);

It worked for me !!