Search code examples
androidfileandroid-download-manager

How to set download path and get the download path?


      request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,nameOfFile);

How to read the downloaded file from that dir.

          File file = new File(Environment.DIRECTORY_DOWNLOADS,nameOfFile);
            MimeTypeMap map = MimeTypeMap.getSingleton();
            String ext = MimeTypeMap.getFileExtensionFromUrl(file.getName());
            String type = map.getMimeTypeFromExtension(ext);

Getting the error that file could not be accessed.


Solution

  • You will have to use the function: getExternalStoragePublicDirectory()

    File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), nameOfFile);
    

    See the Android API Documentation