Get the absolute device path in the phone?

I use Phonegap 3.3.0, before I used 2.5.0, where entry.fullPath will provide the full path to the device. These paths usually look like

/var/mobile/Applications/<application UUID>/Documents/path/to/file  (iOS)
/storage/emulated/0/path/to/file                                    (Android)

since this method is deprecated using the entry.toURL () method to get the path. This method will now return the file system URLs of the form

cdvfile://localhost/persistent/path/to/file

In My application, I pass the URL of the Native function to and from the native file that opens the file. But if I go all the way to Native, iOS will not be able to detect the file. Same thing. If I set the Absolute path hard, the application detects the file.

How to use the file system URL to access the file in its own or any other method to get the absolute path to the device?

Thanks in advance.

+4
3
document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    console.log("device is ready");
    window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}

function fail() {
    console.log("failed to get filesystem");
}

function gotFS(fileSystem) {
    console.log("got filesystem");

        // save the file system for later access
    console.log(fileSystem.root.fullPath);
    window.rootFS = fileSystem.root;
}

function downloadImage(url, fileName){
    var ft = new FileTransfer();
    ft.download(
        url,
        window.rootFS.fullPath + "/" + fileName,
        function(entry) {
            console.log("download complete: " + entry.fullPath);

        },
        function(error) {
            console.log("download error" + error.code);
        }
    );
}
0

toURL() nativeURL :

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){
    console.log("fileSystem.root.toURL()="+fileSystem.root.toURL());
    console.log("fileSystem.root.toInternalURL()="+fileSystem.root.toInternalURL());
    console.log("fileSystem.root.nativeURL="+fileSystem.root.nativeURL);
}, function(){
    alert("fails!");
});

cordova 3.5, iPad:

fileSystem.root.toURL()=file:///Users/myuser/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/1717CB5F-4032-45C7-8CA2-342502447F36/Documents/
fileSystem.root.toInternalURL()=cdvfile://localhost/persistent/
fileSystem.root.nativeURL=file:///Users/myuser/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/1717CB5F-4032-45C7-8CA2-342502447F36/Documents/

... Android- (Genymotion) :

fileSystem.root.toURL()=file:///storage/emulated/0/ 
fileSystem.root.toInternalURL()=cdvfile://localhost/persistent/ 
fileSystem.root.nativeURL=file:///storage/emulated/0/ 
+7
window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);

function gotFS(fileSystem) {
  alert("entered gotFS: " + fileSystem.root.toURL);
}
0
source

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


All Articles