It is not possible to change the location of a local file, for example, cdvfile: //path/index.html in Phonegap 3.5

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

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

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

When you try to change the location, nothing happens. The application remains on 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 that is available for building Phonegap).

Has something changed in Phonegap 3.5.0?

+5
source share
2 answers

For some reason, you just 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 of using the file protocol instead of cdvfile , so there is no problem with policies of the same origin (for example, my other AJAX question is blocked when using cdvfile - Phonegap ).

+3
source

The accepted answer will not work if the file name contains any spaces, since toNativeURL contains url encoding. [This applies to Xcode 5.1 and below, because the data is stored in the Application Support folder.]

To get around this, use:

  • decodeURI (NativeURL); in javascript
  • filepath = [filepath stringByRemovingPercentEncoding]; in Objective-C
0
source

Source: https://habr.com/ru/post/1201526/


All Articles