2016-01-19 108 views
0

我正在構建一個Android應用程序使用HTML5 +科爾多瓦IntelXDK。我正在使用HTML5下載文件,如下所示。獲取Android應用程序下載的文件路徑

<script type='text/javascript'> 
function saveTextAsFile() 
{ 
    var textToWrite = "This Is The Inner Text Of File."; 
    var textFileAsBlob = new Blob([textToWrite], {type:'text/plain'}); 
    var fileNameToSaveAs = "MyFileName.txt"; 

    var downloadLink = document.createElement("a"); 
    downloadLink.download = fileNameToSaveAs; 
    downloadLink.innerHTML = "Download File"; 
    if (window.webkitURL != null) 
    { 
     // Chrome allows the link to be clicked 
     // without actually adding it to the DOM. 
     downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob); 
    } 
    else 
    { 
     // Firefox requires the link to be added to the DOM 
     // before it can be clicked. 
     downloadLink.href = window.URL.createObjectURL(textFileAsBlob); 
     downloadLink.onclick = destroyClickedElement; 
     downloadLink.style.display = "none"; 
     document.body.appendChild(downloadLink); 
    } 
    downloadLink.click(); 


    // alert(filesavedat); // <<<--- Need the downloaded file path here 
} 
</script> 

我不知道天氣用戶只有內存或SD卡,也不知道他/她的默認下載文件夾。我希望在用戶設備在我的JavaScript代碼(變量)中下載後保存該文件的路徑。這是否可能?如果是,那麼如何?

回答

0

在原生應用程序開發中,您可以使用以下方法訪問下載目錄。

Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); 

本質上在科爾多瓦文件API中,必須有一些方法在後端執行此操作。

相關問題