我正在尝试使用PhoneGap从服务器下载文件并将其保存到设备的内部存储器中。以下是我目前的代码:
问题在于当我提供绝对文件路径来下载,例如
if(ionic.Platform.isAndroid()){
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){
fileSystem.root.getFile("test.mp3", {
create: true,
exclusive: false
}, function(fileEntry){
var sPath = fileEntry.fullPath; // equals /test.mp3
// sPath = "file:///storage/sdcard0/test.mp3";
var fileTransfer = new FileTransfer();
fileEntry.remove();
fileTransfer.download(
ringtone.streamUrl,
sPath,
function(theFile){
alert(theFile);
}
);
});
}, null);
}
问题在于当我提供绝对文件路径来下载,例如
file:///storage/sdcard0/test.mp3
,它可以完美地将文件下载到内部存储器中,但如果使用sPath变量,则无法正常工作。据我所知,我无法获取内部存储目录的绝对路径。在android上使用phonegap如何以file:///
格式获取内部存储路径?