6

I am facing tow issues in my app.

1- I am using Android DownloadManager to download online files but it downloads all files to system directories say Download directory by using

request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, "fileName");

Now I want to download the file to my own directory say "New Folder". How is it possible to implement. Please help me in this respect, I would be very thankful.

2- How can I check that whether SD card is available or not?

user1703737
  • 533
  • 1
  • 11
  • 25

1 Answers1

3

DownloadManager

1)

Uri downloadUri = Uri.parse(DOWNLOAD_FILE);
            DownloadManager.Request request = new DownloadManager.Request(downloadUri);
            request.setDescription("Downloading a file");
            long id =  downloadManager.enqueue(request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI |DownloadManager.Request.NETWORK_MOBILE)
                    .setAllowedOverRoaming(false)
                    .setTitle("File Downloading...")
                    .setDescription("Image File Download")
                    .setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "cm.png"));

2)

Boolean isSDPresent = android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);

if(isSDPresent)
{
  // yes download code
}
else
{
 // No sdcard 
}
Nirav Ranpara
  • 13,753
  • 3
  • 39
  • 54