0

I am trying to download a file via DownloadManger in Xamarin Android. I found that HTTPS links are working and HTTP is not. I am not sure if that's the case. I would like to know how to fix this issue.

Android 8: Cleartext HTTP traffic not permitted

if that's the solution I have an unknown number of domains I need to download my data from.

This is working

https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_20mb.mp4

This link is not working

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

}
Taufiq Abdur Rahman
  • 1,348
  • 4
  • 24
  • 44
  • 1
    Have you tried the solution in the link that you provided? I tested your code on my device and met the same problem. When I use the option 3 of the first answer in the link, http uri and https uri both work well. – Liyun Zhang - MSFT Dec 28 '21 at 06:32

1 Answers1

0

Like said in this link just add android:usesCleartextTraffic="true" on your AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.yourappname">

    <application
            android:usesCleartextTraffic="true"
            android:name=".MainApplication"
            android:label="@string/app_name"
            android:icon="@mipmap/ic_launcher"
            android:allowBackup="false"
            android:theme="@style/AppTheme">
    </application>

</manifest>
Taufiq Abdur Rahman
  • 1,348
  • 4
  • 24
  • 44