0

IllegalException at destination folder path

enter image description here

Here is my code am downloading gif images from url

@Override
    protected Void doInBackground(String... strings) {
        String uRl = strings[0];
        DownloadManager mgr = (DownloadManager) context.getSystemService(DOWNLOAD_SERVICE);
        Uri downloadUri = Uri.parse(uRl);
        DownloadManager.Request request = new DownloadManager.Request(
                downloadUri);
        request.setAllowedNetworkTypes(
                DownloadManager.Request.NETWORK_WIFI
                        | DownloadManager.Request.NETWORK_MOBILE)
                .setAllowedOverRoaming(false).setTitle("Demo")
                .setDescription("Something useful. No, really.")
                .setTitle("Downloading giphy file")
                .setDestinationInExternalPublicDir("/IslamicGif", "fileName.gif");
        mgr.enqueue(request);
        return null;
    }
Community
  • 1
  • 1
Najaf Ali
  • 1,433
  • 16
  • 26
  • 1
    Does your app have permission to `write_external_storage` ? And do these help you http://stackoverflow.com/a/17112536/1168654 or http://stackoverflow.com/a/13056375/1168654 ? – Gert Kommer Jul 31 '17 at 08:09
  • yes i have add both permissions – Najaf Ali Jul 31 '17 at 08:11
  • 1
    And you also check that you have permission i presume? https://developer.android.com/training/permissions/requesting.html#make-the-request – Gert Kommer Jul 31 '17 at 08:14
  • thanks a lot for my help i have get the answer right about you asking :https://stackoverflow.com/questions/16773348/set-custom-folder-android-download-manager – Najaf Ali Jul 31 '17 at 08:17
  • I was missing the directory folder properly it was not managed so i got it thank you so much File mydownload = new File (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+ "/myFolder"); if (!mydownload.exists()){ mydownload.mkdir(); } – Najaf Ali Jul 31 '17 at 08:18

1 Answers1

0

Actually i have not manage the directory path perfectly so the error comes its working with this path now.

 File mydownload = new File (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+ "/myFolder");
    if (!mydownload.exists()){
        mydownload.mkdir();
    }
    String url = sUrl[0];
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        request.allowScanningByMediaScanner();
        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    }
    request.setDestinationInExternalPublicDir(mydownload.getAbsolutePath(),"Myfile.extension");
    DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
    manager.enqueue(request);
Najaf Ali
  • 1,433
  • 16
  • 26