Android Concept | Techbirds

Downloading video from webview using the API DownloadManager (which internally uses a asyntask):-
public void DownloadFromUrl(String url, String fileName) {

String extension = MimeTypeMap.getFileExtensionFromUrl(url); if (extension != null) { MimeTypeMap mime = MimeTypeMap.getSingleton(); String mimeType = mime.getMimeTypeFromExtension(extension); if (mimeType != null) { if (mimeType.toLowerCase().contains(“video”) || extension.toLowerCase().contains(“mov”) || extension.toLowerCase().contains(“mp4″) || extension.toLowerCase().contains(“m4v”)) { DownloadManager mdDownloadManager = (DownloadManager) DisplayDownloadingActivity.this .getSystemService(Context.DOWNLOAD_SERVICE); DownloadManager.Request request = new DownloadManager.Request( Uri.parse(url)); File f = new File(Environment.getExternalStorageDirectory() + File.separator + “VideoCollection” + File.separator + fileName); f.mkdirs(); File destinationFile = new File( Environment.getExternalStorageDirectory() + File.separator + “VideoCollection” + File.separator + fileName

+ File.separator + mydate + “.mp4″);

request.setDescription(“Downloading via Your app name..”); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); request.setDestinationUri(Uri.fromFile(destinationFile));

mdDownloadManager.enqueue(request);

} else { Toast.makeText(DisplayDownloadingActivity.this, “file is not downloadable…try other “, Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(DisplayDownloadingActivity.this, “unable to download this file “, Toast.LENGTH_SHORT) .show(); } }

}

427 total views, 1 views today

Share this Onfacebook-2448117twitter-4919186linkedin-4468743google-8615390