你可以把你的操作爲Observable<Status>
其中
public static class Info {
public final long contentLength;
public final String mimeType;
public final String nameHint;
public Info(long contentLength, String mimeType, String nameHint) {
this.contentLength = contentLength;
this.mimeType = mimeType;
this.nameHint = nameHint;
}
}
public static class Status {
public final Info info;
public final long downloadProgress; //in bytes
public final Optional<File> file;
public Status(Info info, long downloadProgress, Optional<File> file) {
this.info = info;
this.downloadProgress = downloadProgress;
this.file = file;
}
}
然後,你可以在你的下載運營模式爲:
Observable<Status> download();
你沒有排放,直到下載已經開始和最後的發射有File
結果。
你可以使用這樣的:
download()
.doOnNext(status -> System.out.println(
"downloaded "
+ status.downloadProgress
+ " bytes of " + status.contentLength))
.last()
.doOnNext(status -> System.out.println(
"downloaded " + status.file.get())
.doOnError(e -> logError(e))
.subscribe();
你想要什麼要執行的操作? –
@TassosBassoukos添加了一個示例回調接口 –