I\'m currently using Retrofit by Square for Android network communications. Is there a way to get its progress during a task to create a progress notification, something sim
If you want to get the max value in order to show it on a ProgressDialog, Notification, etc.
ProgressListener
public interface ProgressListener {
void transferred(long num, long max);
}
CountingTypedFile
public class CountingTypedFile extends TypedFile {
private static final int BUFFER_SIZE = 4096;
private final ProgressListener listener;
public CountingTypedFile(String mimeType, File file, ProgressListener listener) {
super(mimeType, file);
this.listener = listener;
}
@Override
public void writeTo(OutputStream out) throws IOException {
byte[] buffer = new byte[BUFFER_SIZE];
FileInputStream in = new FileInputStream(super.file());
long total = 0;
try {
int read;
while ((read = in.read(buffer)) != -1) {
total += read;
this.listener.transferred(total, super.file().length());
out.write(buffer, 0, read);
}
} finally {
in.close();
}
}
}