Search code examples
androidurlandroid-download-manager

file is not downloading via DownloadManager in Android


Hi i want to download video file and below is my code

public void file_download(String uRl) {
      File direct = new File(Constant.FOLDER_PATH);
      try {
       uRl = "http://songs7.funmaza.in/videos/"
         + URLEncoder
           .encode("Issey Kehte Hain Hip Hop 720p - Yo Yo Honey Singh [Funmaza.com].wmv",
             "UTF-8");
      } catch (UnsupportedEncodingException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }
      System.out.println("URL For Download == " + uRl);
      if (!direct.exists()) {
       direct.mkdirs();
      }
      DownloadManager mdDownloadManager = (DownloadManager) ((Activity) context)
        .getSystemService(Context.DOWNLOAD_SERVICE);
      DownloadManager.Request request = new DownloadManager.Request(
        Uri.parse(uRl));
      request.setDescription("Downloading via Your app name..");
      request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
      request.setDestinationUri(Uri.fromFile(direct));
      mdDownloadManager.enqueue(request);

     }

and in download manager I got following information

enter image description here

If i pass simple URL like "http://beta-vidizmo.com/hilton.mp4" then it is working fine


Solution

  • Finally Try and error, I found this solution,

        File direct = new File(Constant.FOLDER_PATH);
          uRl = "http://songs7.funmaza.in/videos/Issey Kehte Hain Hip Hop 720p - Yo Yo Honey Singh [Funmaza.com].wmv";
          uRl = uRl.replace(" ", "%20");
          uRl = uRl.replace("[", "%5B");
          uRl = uRl.replace("]", "%5D");
          System.out.println("URL For Download == " + uRl);
          if (!direct.exists()) {
           direct.mkdirs();
          }
          DownloadManager downloadManager = (DownloadManager) ((Activity) context)
            .getSystemService(Context.DOWNLOAD_SERVICE);
          DownloadManager.Request request = new DownloadManager.Request(
            Uri.parse(uRl));
          request.setAllowedNetworkTypes(
            DownloadManager.Request.NETWORK_WIFI
              | DownloadManager.Request.NETWORK_MOBILE)
            .setAllowedOverRoaming(false)
            .setDescription("Downloading via Your app name..")
            .setTitle("Issey Kehte Hain Hip Hop")
            .setNotificationVisibility(
              DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
            .setDestinationInExternalPublicDir("/MoviesAndSongs",
              "test1.mp4");
          downloadManager.enqueue(request);
    

    It's done :) Thanks Haresh to you also