Tharindu Wanninayake
Tharindu Wanninayake

Reputation: 353

Xamarin native android DownloadManager "Download unsuccessful" error

I'm new to Xamarin and I'm using DownloadManager to download pdf,excel,word documents. Notification says "Download unsuccessful". But the file that I want to download is downloading to the correct path. Can someone help me with this.

This is my code.

var source = Android.Net.Uri.Parse(reportUrl);
var request = new DownloadManager.Request(source);
request.AllowScanningByMediaScanner();
request.SetNotificationVisibility(DownloadVisibility.VisibleNotifyCompleted);
request.SetDestinationInExternalPublicDir(Android.OS.Environment.DirectoryDownloads, source.LastPathSegment);
var manager = (DownloadManager)Activity.GetSystemService(Android.Content.Context.DownloadService);
manager.Enqueue(request);

Upvotes: 1

Views: 1440

Answers (1)

Billy Liu
Billy Liu

Reputation: 2168

I have tested your code and reproduce your issue. I solve it by adding request.SetAllowedOverRoaming(false) to the code.

For example:

        var source = Android.Net.Uri.Parse(reportUrl);
        var request = new DownloadManager.Request(source);
        request.AllowScanningByMediaScanner();           
        request.SetAllowedOverRoaming(false);
        request.SetNotificationVisibility(DownloadVisibility.VisibleNotifyCompleted);
        request.SetDestinationInExternalPublicDir(Android.OS.Environment.DirectoryDownloads, source.LastPathSegment);
        var manager = (DownloadManager)this.GetSystemService(Android.Content.Context.DownloadService);
        manager.Enqueue(request);

Add make sure your reportUrl is correct.

Upvotes: 0

Related Questions