【发布时间】:2015-10-16 03:24:11
【问题描述】:
我正在尝试从服务器下载文件,然后使用 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 变量则不起作用。据我了解,我无法获得内部存储目录的绝对路径。我们如何使用phonegap在android中获取file:///格式的内部存储路径。
【问题讨论】: