2

I am sending files (up to 100Mo on my android handled) using the Channel Api.

I decided to create a handler to update the progress of the transfer to that the user is aware of the progress.

I use the Message Api to send the file size to my handled and I update the progress checking each x milliseconds the size of the file.

The matter is that I don't know first if that's a good way of doing what I want, and second, due to the fact that it's asynchronous, I have to wait that I correctly received the file size in the onMessageReceived before sending the file.

krakig
  • 1,515
  • 1
  • 19
  • 33

1 Answers1

1

If you are using ChannelApis, you can use the low level version of transfer (using output stream and input stream) and then on the sender side, you can update your progress bar with the amount that you are writing to the output stream. If you are using sendFile() method, you don't have any view into the progress on the sender side so you need to report that back using, say, Message Apis as you are doing. Instead of doing that at x milliseconds, you may decide to make it a bit smarter; if you have the size of the whole file, you probably wouldn't want to send a message if the visual change in the progress bar is not going to be much or noticeable; in other words, try to reduce the number of communications as much as possible.

Ali Naddaf
  • 16,951
  • 2
  • 21
  • 28
  • I didn't explain clearly what I do : I send a message before transfering the file with its size so then I can call a timer on the handled side to update the progress bar each x milliseconds – krakig Sep 04 '15 at 07:21