public void StartDownload(Android.App.DownloadManager downloadManager, string destinationPathName, bool allowedOverMetered, DownloadVisibility notificationVisibility, bool isVisibleInDownloadsUi) { using (var downloadUrl = Uri.Parse(Url)) using (var request = new Android.App.DownloadManager.Request(downloadUrl)) { if (Headers != null) { foreach (var header in Headers) { request.AddRequestHeader(header.Key, header.Value); } } if (destinationPathName != null) { var file = new Java.IO.File(destinationPathName); var uriPathFile = Android.Net.Uri.FromFile(file); request.SetDestinationUri(uriPathFile); //if (file.Exists()) //{ // file.Delete(); //} } request.SetVisibleInDownloadsUi(isVisibleInDownloadsUi); request.SetAllowedOverMetered(allowedOverMetered); request.SetNotificationVisibility(notificationVisibility); Id = downloadManager.Enqueue(request); } }
static void Download(Uri uri) { string fileName = Path.GetFileName(uri.LocalPath); Android.App.DownloadManager downloadManager = (Android.App.DownloadManager)Application.Context.GetSystemService("download"); Android.App.DownloadManager.Request request = new Android.App.DownloadManager.Request(Android.Net.Uri.Parse(uri.AbsoluteUri)); //Restrict the types of networks over which this download may proceed. request.SetAllowedNetworkTypes(Android.App.DownloadNetwork.Wifi | Android.App.DownloadNetwork.Mobile); //Set whether this download may proceed over a roaming connection. request.SetAllowedOverRoaming(false); //Set the title of this download, to be displayed in notifications (if enabled). //request.SetTitle(title); request.SetVisibleInDownloadsUi(false); //request.SetNotificationVisibility(DownloadVisibility.Hidden); #if DEBUG request.SetNotificationVisibility(DownloadVisibility.Visible); #else request.SetNotificationVisibility(DownloadVisibility.Hidden); #endif request.SetDestinationInExternalFilesDir(Application.Context, Android.OS.Environment.DirectoryDownloads, fileName); //Enqueue a new download and same the referenceId var id = downloadManager.Enqueue(request); MBDownloadManager.DownloadMonitor(id); }
private void Download(string Url, string filename) { Android.Net.Uri contentUri = Android.Net.Uri.Parse(Url); Android.App.DownloadManager.Request r = new Android.App.DownloadManager.Request(contentUri); r.SetDestinationInExternalPublicDir(Android.OS.Environment.DirectoryDownloads, filename); r.AllowScanningByMediaScanner(); r.SetNotificationVisibility(Android.App.DownloadVisibility.VisibleNotifyCompleted); Android.App.DownloadManager dm = (Android.App.DownloadManager)Xamarin.Forms.Forms.Context.GetSystemService(Android.Content.Context.DownloadService); dm.Enqueue(r); var localFolder = Android.OS.Environment.DirectoryDownloads; var MyFilePath = $"file://{localFolder}/{Filename}"; Toast.MakeText(this, MyFilePath, ToastLength.Long).Show(); }
public void Download(string uri, string filename) { Android.Net.Uri contentUri = Android.Net.Uri.Parse(uri); Android.App.DownloadManager.Request r = new Android.App.DownloadManager.Request(contentUri); r.SetDestinationInExternalPublicDir(Android.OS.Environment.DirectoryDownloads, filename); r.AllowScanningByMediaScanner(); r.SetShowRunningNotification(true); r.SetNotificationVisibility(Android.App.DownloadVisibility.VisibleNotifyCompleted); r.SetVisibleInDownloadsUi(true); Android.App.DownloadManager dm = (Android.App.DownloadManager)Xamarin.Forms.Forms.Context.GetSystemService(Android.Content.Context.DownloadService); // dm.NotifyAll(); dm.Enqueue(r); }
public void Download(string uri, string filename) { var contentUri = Android.Net.Uri.Parse(uri); var r = new Android.App.DownloadManager.Request(contentUri); var downloadpath = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).AbsolutePath; var file = new File(Path.Combine(downloadpath, filename)); if (file.Exists()) { return; } r.SetDestinationInExternalPublicDir(Android.OS.Environment.DirectoryDownloads, filename); r.AllowScanningByMediaScanner(); r.SetNotificationVisibility(DownloadVisibility.VisibleNotifyCompleted); dm = (Android.App.DownloadManager)Forms.Context.GetSystemService(Context.DownloadService); _fileId = dm.Enqueue(r); }
public void StartDownload(Android.App.DownloadManager downloadManager, string destinationPathName, bool allowedOverMetered) { using (var downloadUrl = Uri.Parse(Url)) using (var request = new Android.App.DownloadManager.Request(downloadUrl)) { if (Headers != null) { foreach (var header in Headers) { request.AddRequestHeader(header.Key, header.Value); } } if (destinationPathName != null) { request.SetDestinationUri(Uri.FromFile(new Java.IO.File(destinationPathName))); } request.SetAllowedOverMetered(allowedOverMetered); Id = downloadManager.Enqueue(request); } }
static long Download(Uri uri, string filename, string title, IDownloadUpdated2 notify) { Android.App.DownloadManager downloadManager = (Android.App.DownloadManager)Application.Context.GetSystemService("download"); Android.App.DownloadManager.Request request = new Android.App.DownloadManager.Request(Android.Net.Uri.Parse(uri.AbsoluteUri)); //Restrict the types of networks over which this download may proceed. request.SetAllowedNetworkTypes(Android.App.DownloadNetwork.Wifi | Android.App.DownloadNetwork.Mobile); //Set whether this download may proceed over a roaming connection. request.SetAllowedOverRoaming(false); //Set the title of this download, to be displayed in notifications (if enabled). request.SetTitle(title); request.SetVisibleInDownloadsUi(false); //request.SetNotificationVisibility(DownloadVisibility.Hidden); #if DEBUG request.SetNotificationVisibility(DownloadVisibility.Visible); #else request.SetNotificationVisibility(DownloadVisibility.Hidden); #endif request.SetDestinationInExternalFilesDir(Application.Context, Android.OS.Environment.DirectoryDownloads, filename); //Enqueue a new download and same the referenceId var id = downloadManager.Enqueue(request); ThreadPool.QueueUserWorkItem(state => { MBDownloadManager2.DownloadMonitor(id); }); /*new Thread(() => * { * MBDownloadManager2.DownloadMonitor(id); * * }).Start();*/ return(id); }
private void OnDownloadAvailable(YoutubeEntry feed, VideoInfo videoInfo, MediaType mediaType) { Controls.Title.Text = videoInfo.Title; Dm = (DownloadManager) Controls.Activity.BaseContext.GetSystemService(Context.DownloadService); var fileName = DownloadHelper.GetLegalPath(videoInfo.Title) + videoInfo.VideoExtension; var request = new DownloadManager.Request(Android.Net.Uri.Parse(videoInfo.DownloadUri.ToString())); request.SetAllowedNetworkTypes(DownloadNetwork.Wifi | DownloadNetwork.Mobile) .AddRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11") .SetShowRunningNotification(true) .SetAllowedOverRoaming(true) .SetTitle(videoInfo.Title) .SetDescription(fileName) .SetDestinationInExternalPublicDir(Android.OS.Environment.DirectoryDownloads, fileName); Enqueue = Dm.Enqueue(request); }