0

I have a service that will return some PDF bytes (that may be several MB); however the bytes string are embedded in an xml structure:

<response>
   <code>1</code>
   <message>ok</message>
   <bytes>......(here comes the pdf bytes).....</bytes>
</response>

I would like to do a simple http request to read the code tag before I start the download manager to download the bytes. Because the code may indicate an error so I would manage to simply show the message alert to user.

However I believe that using the Download Manager will ease the process of managing the download without interrupting app.

Is it possible to pass the inputstream so that the manager continues the download and appear in Android notification center?

App may not be able to recall the request once the status is known, because the status may change in the following request.

htafoya
  • 18,261
  • 11
  • 80
  • 104

2 Answers2

0

Is it possible to pass the inputstream so that the manager continues the download and appear in Android notification center?

No. It would have to download the entire file.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • any update? I have base64 string which will represent image or pdf file. I need to download it with progress – Zaid Mirza May 30 '19 at 10:00
  • My bad I told you wrong way, actually I want to convert that string to file and save it directory. Im already using FileOutputStream but write(bytes) method doesn't provide any listener to inform it is done with writing bytes – Zaid Mirza May 30 '19 at 11:07
  • 1
    @ZaidMirza: You have to do that yourself: write some bytes, update your progress, write some bytes, update your progress, and so on. – CommonsWare May 30 '19 at 12:14
0

If I understand well your question : if code indicates an error, you don't want to perform the download.

The server creating the XML obviously knows if an error is there. Then if there is an error, why not just leave the bytes empty?

JM Lord
  • 1,031
  • 1
  • 13
  • 29
  • (or even completely leave out the bytes tag) – JM Lord Oct 13 '15 at 18:07
  • Server leaves them empty when there's an error; but the app must know if they are empty or not before it "officialy" starts the download. – htafoya Oct 13 '15 at 18:47
  • Then I'm afraid that I don't understand your use case. Why do you need that? Downloading this virtually empty XML will be very fast. Your error message will appear as fast as the file is downloaded... – JM Lord Oct 13 '15 at 19:54