Using DownloadManager
If we wish to download files or resources but do not need fine control over the actual download, we can hand the task over to the DownloadManager
instance.
How to do it...
We can use the DownloadManager
instance to initiate, cancel, and query downloads:
- As with normal HTTP requests, we need to request permission to access the Internet:
[assembly: UsesPermission(Manifest.Permission.Internet)]
- Then, we get hold of
DownloadManager
so that we can work with it:var manager = DownloadManager.FromContext(this);
- Once we have the manager, we can start downloads using the
Enqueue()
method with aDownloadManager.Request
instance:var request = new DownloadManager.Request(Uri.Parse(uri)); long downloadId = manager.Enqueue(request);
- We can also ...
Get Xamarin Mobile Development for Android Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.