Dev*_*ice 3 android download-manager
我正在使用下载管理器,我想使用自己的webview下载一些音频文件.
我使用以下代码:
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);
Run Code Online (Sandbox Code Playgroud)
即使文件名是audio.mp3,下载管理器也不会识别文件类型.ScreenShot解释了主要问题.

使用默认浏览器下载文件等其他应用程序就像这样!

小智 5
解决方案很简单:只需添加以下行
request.setMimeType("audio/MP3");
Run Code Online (Sandbox Code Playgroud)
更多信息在这里
| 归档时间: |
|
| 查看次数: |
1107 次 |
| 最近记录: |