title: How to detect the extension of file to download using DownloadManager in Android?
body: <p>I start developing my very first Android project. In my project, I need to download media files, especially mp3 or mp4. I am downloading file using DownloadManager.</p>
  
  <p>Here is my download code for mp3</p>
  
  <pre><code>private void downloadPodcast(int id)
      {
          String url = context.getResources().getString(R.string.api_endpoint)+"podcast/download?id="+String.valueOf(id);
  
          DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
          request.setDescription("Downloading...");
          request.setTitle("Podcast");
          request.setMimeType("audio/MP3");
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB) {
              request.allowScanningByMediaScanner();
              request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
          }
          request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "audio.mp3");
          DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
          manager.enqueue(request);
      }
  </code></pre>
  
  <p>As you can see in my code, I am downloading only mp3 and setting the MIME type is constant. The file name and its extension is constant as well. What I want to do is to detect the file extension I will download. So can I set the MIME type programmatically and set the extension of file name. How can I achieve it in DownloadManager?</p>