2014-03-05 94 views
1

我有在Android的PhoneGap的應用程序的要求,我必須表明正在進行的下載和所有下載選項卡並排當用戶下載一些文件,它會只顯示在progess選項卡中,而爲Android顯示在所有下載選項卡上也作爲android創建一個文件結構,然後才能完成下載。我下載之前重命名文件像abc.mp3.download,但下載後我必須將它重命名爲abc.mp3它可以使用但我無法做到。重命名我用下面​​的代碼重命名下載後的文件系統文件中的PhoneGap的Android

fileTransfer.download(elementTitle,filePath, function(entry) { 

var dwnnam = filePath.substring(filePath.lastIndexOf('/')+1,filePath.lastIndexOf('.')); 
alert("file name -- " + dwnnam); 
var destination = "file:///mnt/sdcard/Project/"; 
window.resolveLocalFileSystemURI("file:///mnt/sdcard/TechTime/", 
function(destination) { 
entry.moveTo(destination, "abc.mp3" ,success,fail); 
}) 
+0

Divesh嗨,這有onprogress事件沒有任何聯繫的AREADY出現在我的應用程序 – Music

+0

請提供給我的解決方案重新命名下載的文件 – Music

+0

是什麼ü在logcat中 –

回答

2

下面的代碼爲我工作

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,function (fileSys) { 
    fileSys.root.getDirectory("myFolder", { 
     create: true, 
     exclusive: false 
    }, 
    function (directory) { 
     entry.moveTo(directory, "file.pdf", success, fail); 
    }, fail); 
}, fail); 

function success(fileEntry) { 
    console.log("New Path: " + fileEntry.fullPath); 
} 

function fail(error) { 
    console.log(error.code); 
}