public static void Remove(long id) { Android.App.DownloadManager downloadManager = (Android.App.DownloadManager)Application.Context.GetSystemService("download"); var info = MBDownloadManager2.DownloadInfo(id); var uri = new Uri(info.Uri); downloadManager.Remove(id); if (pendingRequests != null && pendingRequests.ContainsKey(uri)) { pendingRequests.Remove(uri); if (queuedUpdates.Contains(uri)) { queuedUpdates.Remove(uri); } } }
private static void DownloadMonitor(long downId) { bool downloading = true; Android.App.DownloadManager downloadManager = (Android.App.DownloadManager)Application.Context.GetSystemService("download"); while (downloading) { DownloadInfo down = MBDownloadManager2.DownloadInfo(downId); if (down == null) { break; } Uri uri = new Uri(down.Uri); switch (down.Status) { case DownloadStatus.Running: case DownloadStatus.Pending: if (MBDownloadManager2.pendingRequests.ContainsKey(uri)) { List <IDownloadUpdated2> list = MBDownloadManager2.pendingRequests[uri]; var perc = (int)((down.ByteDownloaded * 100L) / down.ByteTotal); try { foreach (IDownloadUpdated2 current2 in list) { current2.ProgressChanged(perc); } } catch (Exception value) { Console.WriteLine(value); } } break; case DownloadStatus.Successful: try { MBDownloadManager2.InstallMbPackage(down.Uri, down.LocalUri); downloadManager.Remove(down.Id); downloading = false; MBDownloadManager2.RegisterDownload(uri.ToString(), down.LocalUri); MBDownloadManager2.FinishDownload(uri, true); } catch (Exception value) { Console.WriteLine(value); MBDownloadManager2.FinishDownload(uri, false); } break; default: break; } } }