【发布时间】:2021-12-27 18:17:00
【问题描述】:
我正在尝试通过 Xamarin Android 中的 DownloadManger 下载文件。我发现 HTTPS 链接有效,而 HTTP 无效。我不确定是不是这样。我想知道如何解决这个问题。
Android 8: Cleartext HTTP traffic not permitted
如果这是解决方案,我需要从未知数量的域中下载我的数据。
这是有效的
https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_20mb.mp4
这个链接失效了
http://www.candybd.net/upload/source/movies/HINDI/2019/Chaal Jeevi Laiye (2019) Gujarati Pre CAMRip/Chaal Jeevi Laiye 2019 Gujarati Pre CAMRip x264 AAC CiNEVooD.net.mp4
private void BtnMovieViewDownloadClick(object sender, System.EventArgs e)
{
var downloadPath = Url;
var decode = Uri.Decode(downloadPath);
var fileNameWithoutExt = Path.GetFileNameWithoutExtension(decode);
var fileName = Path.GetFileName(decode);
Uri uri = Uri.Parse(decode);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.SetAllowedNetworkTypes(DownloadNetwork.Wifi | DownloadNetwork.Mobile);
request.SetNotificationVisibility(DownloadVisibility.Visible);
request.SetAllowedOverMetered(true);
request.SetVisibleInDownloadsUi(true);
request.SetDestinationInExternalFilesDir(this, Environment.DirectoryDownloads, fileName);
request.SetTitle(fileNameWithoutExt);
request.SetDescription("File is Downloading...");
var manager = (DownloadManager)GetSystemService(DownloadService);
long downloadId = manager.Enqueue(request);
}
【问题讨论】:
-
您是否尝试过您提供的链接中的解决方案?我在我的设备上测试了您的代码并遇到了同样的问题。当我在链接中使用第一个答案的选项 3 时,http uri 和 https uri 都可以正常工作。
标签: c# android http https xamarin.android