【问题标题】:Xamarin native android DownloadManager "Download unsuccessful" errorXamarin native android DownloadManager“下载不成功”错误
【发布时间】:2018-06-04 13:05:16
【问题描述】:

我是 Xamarin 的新手,我正在使用 DownloadManager 下载 pdf、excel、word 文档。通知显示“下载失败”。但是我要下载的文件正在下载到正确的路径。有人可以帮我解决这个问题吗?

这是我的代码。

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

【问题讨论】:

    标签: android xamarin xamarin.android


    【解决方案1】:

    我已经测试了您的代码并重现了您的问题。我通过在代码中添加request.SetAllowedOverRoaming(false) 来解决它。

    例如:

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

    添加确保您的reportUrl 正确。

    【讨论】:

    • 我需要漫游选项为“true”,无论如何我添加了“request.SetAllowedOverRoaming(boolean)”为“false”来测试。但它仍然不适用于 Nougat 以下的操作系统。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-05
    相关资源
    最近更新 更多