[英]Downloaded mp3 files can't open in Downloads folder (Android Studio)
我有一個可從網址下載mp3文件的應用。 下載正常,我在downloads文件夾中得到一個文件。 但是,當我單擊它時,它顯示“無法打開文件”。 當我使用getExternalStorageDirectory()時,它也不會檢索文件或獲取任何信息。 我實現下載功能的方式有問題嗎? 還是我與下載管理器還有更多關系? 我也嘗試使用addCompletedDownload(),但是它只會添加一個“ 0”文件。
private long DownloadData (Uri uri) {
long downloadReference;
downloadManager = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
// Create request for android download manager
DownloadManager.Request request = new DownloadManager.Request(uri);
//Setting title of request
request.setTitle("Downloading Song");
//Setting description of request
request.setDescription("Downloading Song from URL");
//Set the local destination for the downloaded file to a path within the application's external files directory
request.setDestinationInExternalFilesDir(MainActivity.this, Environment.DIRECTORY_DOWNLOADS, "DownloadSong.mp3");
//Enqueue download and save into referenceId
downloadReference = downloadManager.enqueue(request);
return downloadReference;
}
您顯示給我們的代碼絕對不足以理解問題。 這是使用DownloadManager
的示例代碼。
根據描述的症狀,我認為您沒有正確完成下載操作或寫入操作。 您應該檢查下載是否完成以及文件是否已寫入並關閉。 出現文件的事實意味着下載和寫入已經開始,但未正確完成下載。
使用DownloadManager術語,應completed
。 查看如何從Android下載管理器完成所有下載后通知該問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.