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); }
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); }