下载管理器无法识别.mp3文件

时间:2014-08-08 17:38:20

标签: android download-manager

我正在使用下载管理器 我想用自己的网页浏览下载一些音频文件。

我使用以下代码:

        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url2));
        request.setDescription("Downloading");
        request.setTitle("File :");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            request.allowScanningByMediaScanner();
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
        }
        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "audio.mp3");
        DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
        manager.enqueue(request);

即使文件名是audio.mp3,下载管理器也不会识别文件类型。 ScreenShot解释了主要问题。

enter image description here

使用其他应用程序(如默认浏览器下载的文件)就像这样! enter image description here

2 个答案:

答案 0 :(得分:5)

解决方案很简单: 只需添加以下行

即可
request.setMimeType("audio/MP3");

更多信息here

答案 1 :(得分:0)

不起作用:request.setMimeType(“ audio / MP3”);

要操作,请按照以下步骤操作。

request.setMimeType(“ audio / mpeg”);

相关问题