Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Device absolute path in phonegap?

I'm using Phonegap 3.3.0, earlier i used 2.5.0 where entry.fullPath will give the Device full path. These paths would typically look like

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

since that method is deprecated am using entry.toURL() method to get the path.This method will now return filesystem URLs of the form

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

In My application, am passing the URL to Native function and from native am opening a file. But If I pass the path to Native, iOS could not able to detect the file. The same If i hardcode the Absolute path, application detects the file.

How to use the fileSystem URL to access the file in native or any other method to get the device absolute path ?

Thanks in advance.

like image 581
Mohammed Imran N Avatar asked Mar 20 '23 18:03

Mohammed Imran N


1 Answers

The toURL() method or the nativeURL attribute should return the result wanted:

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!");
});

Using cordova 3.5, the output in iPad simulator is:

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/

...and in Android simulator (Genymotion) is:

fileSystem.root.toURL()=file:///storage/emulated/0/ 
fileSystem.root.toInternalURL()=cdvfile://localhost/persistent/ 
fileSystem.root.nativeURL=file:///storage/emulated/0/ 
like image 118
leo Avatar answered Mar 29 '23 00:03

leo