O'Reilly logo

Xamarin Mobile Development for Android Cookbook by Matthew Leibowitz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

  1. As with normal HTTP requests, we need to request permission to access the Internet:
    [assembly: UsesPermission(Manifest.Permission.Internet)]
  2. Then, we get hold of DownloadManager so that we can work with it:
    var manager = DownloadManager.FromContext(this); 
  3. Once we have the manager, we can start downloads using the Enqueue() method with a DownloadManager.Request instance:
    var request = new DownloadManager.Request(Uri.Parse(uri));
    long downloadId = manager.Enqueue(request);
  4. We can also ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required