I have a video file(.MP4 format) and I want to allow the user to be able to download the video to their SD card.I currently use this code but its not working..
First get Url from database then parse it in to URI and paste video uri in to DownloadManger constructor . I am retriving URL from firebase database with help to onComplete listiner.
viewHolder.ll_download.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String vdoUri = task.getResult().toString();
try {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(vdoUri));
request.setDescription("download");
request.setTitle(itemlist.get(position).getFile_name());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, ""+itemlist.get(position).getFile_name()+".mp4");
DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
}
catch (Exception ex) {
}
}
});