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?
You can enable saving to your SD card using the Files app on the latest version of Android. If files do not save to the SD card automatically, you can transfer them to the SD card using the Files app on stock Android, or the My Files app on Samsung Galaxy.
You can find your downloads on your Android device in your My Files app (called File Manager on some phones), which you can find in the device's App Drawer. Unlike iPhone, app downloads are not stored on the home screen of your Android device, and can be found with an upward swipe on the home screen.
use this way: Here Dhaval_files is my folder name
public void file_download(String uRl) {
File direct = new File(Environment.getExternalStorageDirectory()
+ "/dhaval_files");
if (!direct.exists()) {
direct.mkdirs();
}
DownloadManager mgr = (DownloadManager) this.getSystemService(Context.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.")
.setDestinationInExternalPublicDir("/dhaval_files", "test.jpg");
mgr.enqueue(request);
}
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With