I used the following code to make it work in my Xamarin Droid project using C #:
// Suppose this is your local file var file = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }; var fileName = "myFile.pdf"; // Determine where to save your file var downloadDirectory = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, Android.OS.Environment.DirectoryDownloads); var filePath = Path.Combine(downloadDirectory, fileName); // Create and save your file to the Android device var streamWriter = File.Create(filePath); streamWriter.Close(); File.WriteAllBytes(filePath, file); // Notify the user about the completed "download" var downloadManager = DownloadManager.FromContext(Android.App.Application.Context); downloadManager.AddCompletedDownload(fileName, "myDescription", true, "application/pdf", filePath, File.ReadAllBytes(filePath).Length, true);
Now your local file is “downloaded” to your Android device, the user is notified, and the link to the file is added to the download folder. However, make sure that the user asks for permission before you write to the file system, otherwise the "access denied" exception will be thrown.
source share