0

I've got the task to develop a Chat App using Android, things sent between users are Text and Images, when User1 sends User2 an Image File, User2 has to first accept the request, and then file will be sent.

My Problem is, when User2 accepts the File Send Request, I still need to somehow know, that File Download has completed, to view the Image, how can I do that.

Is there an already defined Event in Android or Java, that I can listen to and Handle upon fileDownlaodCompletion? I appreciate help of any kind.

StaticBug
  • 557
  • 5
  • 15

1 Answers1

1

File downloading is accomplished in many different ways. HTTP, FTP, SCP or straight Sockets. Because of this, there is no standard mechanism for when a file is downloaded. BAsed on the mechanism you use to do the file download, you will need to interact with the library to determine when the download is complete.

For instance, with the Apache HTTP-client, you need to point at the http address and then read the HttpEntity.content() stream to get the content out. Because of this, the reading of the content as well as the entire connection is usually off loaded to another thread. Then, as you suggested, you can create a 'downloadComplete(File file)' call back that will do what you hoped.

Take a look at this great answer for a complete example. Just implement a call back mechanism to get called when you are finished with the download, like my previous answer here.

Community
  • 1
  • 1
Nick Campion
  • 10,479
  • 3
  • 44
  • 58