Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot change location to local file eg cdvfile://path/index.html in Phonegap 3.5

My app copies files on the device using the FileAPI. This works well in Phonegap 3.4.0 and 3.5.0.

Then it opens an html file by doing window.location = "cdvfile://localhost/persistent/TEST/index.html"; (note that the path is not hard coded but uses something like myDirEntry.toURL(), and that both 3.4 and 3.5 give the same path).

This works well in 3.4.0 (tested on several versions of Android and iOS), but it does not work in 3.5.0 (tested only on Android 4.1.2 and 4.4.2).

When trying to change the location, nothing happens. The app stays in the current page, no exception seems to be thrown.

In both cases I use the org.apache.cordova.file plugin version 1.0.1 (the one available on Phonegap Build).

Has something changed in Phonegap 3.5.0?

like image 603
user276648 Avatar asked Sep 01 '14 01:09

user276648


1 Answers

For some reason you simply need to use toNativeURL instead of toURL in Phonegap 3.5 (tested on Android):

  • toURL gives me cdvfile://localhost/persistent/Path/To/Folder
  • toNativeURL gives me file:///storage/sdcard0/Path/To/Folder

Using toNativeURL has the advantage to use the file protocol instead of cdvfile, so that there's no same-origin policy issue (cf my other question AJAX blocked when using cdvfile - Phonegap).

like image 177
user276648 Avatar answered Sep 28 '22 07:09

user276648