簡體   English   中英

在Android應用程序中獲取下載的文件路徑

[英]Get Downloaded File Path In Android Application

我正在使用IntelXDK中的 HTML5 + Cordova構建一個Android應用程序。 我正在使用HTML5下載文件,如下所示。

<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代碼(變量)后,無論用戶設備將其保存到哪里,我都希望獲得該文件的路徑。 這有可能嗎? 如果是,那怎么辦?

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

Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);

本質上,在Cordova文件API中,后端必須有一些方法來執行此操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM