3

I am using Download Manager and i want to download some audio files using my own webview.

I use the following code:

        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);

Even if the the File Name is audio.mp3 download manager does not recongise the file type. ScreenShot explains the main problem.

enter image description here

Using other apps like default browser downloaded files look like this! enter image description here

Device
  • 993
  • 3
  • 11
  • 26

2 Answers2

5

The solution is simple: Just add the following line

request.setMimeType("audio/MP3");

More info here

0

not work : request.setMimeType("audio/MP3");

To operate, follow the steps below.

request.setMimeType("audio/mpeg");