I am trying to download file from Java Spring backend to my Xamarin Forms app. I am using native Android manager. When I start download, I see new file in Files, and soon it starts downloading, finally reaching 100%. Immediately after that, the file goes to Queued status. After some time, it says that download is unsuccessful. When I read the status, reason code is 1008, which means ERROR_CANNOT_RESUME. However, what there is to resume if download went to 100%? This happens only on Android 9, I tried with both 7 and 8.1 and it works without any errors.
Xamarin code:
public long download(string url, string filePath, string token) {
var manager = (Android.App.DownloadManager)Android.App.Application.Context.GetSystemService(Context.DownloadService);
var source = Android.Net.Uri.Parse(url);
var request = new DownloadManager.Request(source);
request.AllowScanningByMediaScanner();
request.SetNotificationVisibility(DownloadVisibility.VisibleNotifyCompleted);
//request.SetDestinationInExternalPublicDir(Android.OS.Environment.DirectoryDownloads, source.LastPathSegment);
request.AddRequestHeader("Authorization", "Bearer " + token);
request.AddRequestHeader("Content-type", "application/octet-stream");
long downloadId = manager.Enqueue(request);
return downloadId;
}
Java backend code:
@RequestMapping(path = "/download/{idBook}/{idDevice}", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public void download(@PathVariable int idBook, @PathVariable String idDevice, HttpServletRequest request, HttpServletResponse response) throws Exception
{
String rangestring = request.getHeader("Range");
//System.out.println(rangestring);
if(rangestring != null)
{
String[] strings = (rangestring.substring(6)).split("-");
}
Book book = myBookRepository.getOne(idBook);
String fileName = fileUtil.getFilePath(idBook);
MultipartFileSender.fromFile(new File(fileName))
.with(request)
.with(response)
.serveResource();
}
And MultipartFileSender is taken from here