In some occasions, when trying to download a file with the Android DownloadManager, the download failed and the download notification shows "Unsuccessful download".
After some hours of debugging, I realized some of the headers that I was passing to the download manager were null or empty. Especially the "User-Agent", when that happens the download manager posts a notification saying "Unsuccessful download".
val androidDownloadManager = applicationContext.getSystemService(DOWNLOAD_SERVICE) as AndroidDownloadManager
val request = Request(Uri.parse(download.url))
request.addRequestHeader("User-Agent", download.userAgent)
androidDownloadManager.enqueue(request)
Related
i am download file on my ftp server, but if i using android emulator then sometimes return different error.(File corrupted , Remote prematurely closed connection or auth error) but sometimes is worked perfect.
Example 20 download
5 download success.
2 fail
3 success
2 fail.
Why ?
Can i solved this problem ? What can i do.
Thank you.
Edit:
The problem occurs when I connect via ftp via android emulator and try to download files.
clientFluentFTP.LoadProfile(new FtpProfile
{
Host = host,
Credentials = new NetworkCredential(ftpUsername, ftpPassword),
Encryption = FtpEncryptionMode.Explicit,
Protocols = SslProtocols.Tls12,
DataConnection = FtpDataConnectionType.PASV,
Encoding = System.Text.Encoding.UTF8,
});
clientFluentFTP.ValidateAnyCertificate = true;
clientFluentFTP.Connect();
clientFluentFTP.DownloadFile(nereyeindir, "veritabani/" + "xx.zip", FtpLocalExists.Overwrite, FtpVerify.Throw);
I am trying to download a file using DownloadManager, but I have a few scenarios to make decision on download response.
How to get success response message from download manager?
I have an application in which we have files that are being served from a secure encrypted file system to the user. THe files are decrypted on the fly by the application and then pushed to the client through the response header. This works perfectly fine in all browsers and iOS devices, but fails on all androids. It just simply says the download failed.
I have tried many different solutions that have been suggested around for android devices, as they seem to have a lot of problems with files like this. Nothing has seemed to work.
change file extension to be in all caps in the Content-Disposition header
tried multiple content types (application/octet-stream and specific file types)
Below is the actual code writing the response headers.
strMimeType = objDocument.FileMime
If strMimeType = "" Then
strMimeType = "application/octet-stream"
End If
HttpContext.Current.Response.ContentType = strMimeType
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" & objDocument.Filename)
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.WriteFile(Server.MapPath("/FS/CO/" & objDocument.DocumentID & "/" & objDocument.Filename))
HttpContext.Current.Response.Flush()
HttpContext.Current.Response.Close()
HttpContext.Current.Response.End()
this worked for me - adb logcat DownloadManager:I *:S
that shows in the adb logcat only things from the downloadmanager. i am on a samsung galaxy s4 so if you have something different and you probably do you have to find out the name of your download manager by google, or start the log : use "adb logcat" do that, and then download the file then quickly scroll up to stop the adb from printing more stuff, and then find it.
i got this problem:
I/DownloadManager( 9250): Initiating request for download id = 2011 with mAllowedNetworkTypes = -1 forP2Pbit = 8194
W/DownloadManager( 9250): Aborting request for download 2011: http error 403, mContinuingDownload: false FinalStatus = 403
i think it has something to do with my server but my server works just fine. so im not sure why it is breaking
In my Android app I have to download files from URLs. I use the Android DownloadManager but the URLs are accessible only through a DefaultHttpClient. Infact these URLs are the result of several POST requests. I mean: I'm allowed to download the files only if I'm logged in as user. Could someone help me in managing this situation? I think that it's not possibile to use the DM to download the files by putting directly the link of the requested resource. When I have to download a file there already is an active DefaultHttpClient and I'm logged in.
The code I use is the following:
dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
Request request = new Request(Uri.parse(client.HttpsGet(url));
enqueue = dm.enqueue(request);
The HttpsGet is a method of my custom class HttpsClient that does a HTTP GET. In this case I obtain the file encoded in text (like if I open a pdf with notepad). If I directrly put the url of the file (without calling the HttsGet) the devices downloads a blank file.
For posterity...
I solved my problem thanks to this thread: How do download a file with login using HttpURLConnection
But I had to renounce to the DownloadManager
Hope this helps!
Grails 1.3.7
I have some code that looks like this...
response.setHeader("Content-disposition", "attachment; filename=${fileName}")
response.contentType = download.contentType
response.contentLength = file.length()
response.outputStream << file.getBytes()
On the desktop and on the iPad, the downloads work just fine. But on android devices it just gives me "Unknown myserver.com In progress". And then eventually fails. A couple of points...
This happens locally, staging, and on production servers
Testing without SSL, everything works fine.
When I try the download in the Dolphin Browser I get the same results
with an added bit of text "Waiting for data connection"
Update #2: Stacktrace that only occurs when downloading from an Android device:
Stacktrace follows:
java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at com.sun.net.ssl.internal.ssl.OutputRecord.writeBuffer(OutputRecord.java:297)
at com.sun.net.ssl.internal.ssl.OutputRecord.write(OutputRecord.java:286)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecordInternal(SSLSocketImpl.java:743)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:731)
at com.sun.net.ssl.internal.ssl.AppOutputStream.write(AppOutputStream.java:59)
at com.wbr.consumer.ProductController$_closure1_closure2.doCall(ProductController.groovy:30)
at com.wbr.consumer.ProductController$_closure1.doCall(ProductController.groovy:28)
at com.wbr.consumer.ProductController$_closure1.doCall(ProductController.groovy)
at java.lang.Thread.run(Thread.java:680)
I realize this is a few months late but I also ran into this issue with the Android browser and a Grails application I was working on.
The issue appears to be how Android handles downloadable content and the android browser integration with download manager.
http://code.google.com/p/android/issues/detail?id=1978
http://code.google.com/p/android/issues/detail?id=18462
I was receiving two requests on the server side for a downloadable file; one from the browser and one from the download manager. The one from the browser ends up getting terminated and the socket closed as soon as the browser determines that it is downloadable content. The browser then hands off the download to the download manager.
I was also having issues with the download failing from download manager but that had to due with me not sending headers as soon as they were ready. I ran into this only with larger APKs, small APKs (under 10-20K) seemed to download just fine.
Some code may help:
response.contentType = 'application/vnd.android.package-archive'
response.addHeader('Content-Disposition', 'attachment; filename=FILENAME.APK')
// output file content
response.setStatus(200)
response.setContentLength("CONTENTSIZE")
// send headers
response.flushBuffer()
try {
response.outputStream << {FILE}.getBytes()
response.outputStream.flush()
} catch (SocketException e) {
log.error(e)
}
return
With this, I always end up with one socket exception. Don't know if thats avoidable, from some quick searching I didn't see a way to determine socket state from servlet without simply trying to write to the socket.
It sounds like there are potentially 2 issues
the browser you are using does not trust the self signed cert.
Do other SSL sites work from this browser?
Can you install your STG
cert into the browser's trusted certs store?
A stupid question is : did you get the request URL correct? https vs http ... i know it's stupid.....
the response is never flushed to the client. Try this:
response.outputStream.flush()