title: Download progress with RxJava, OkHttp and Okio in Android
body: <p>In our app I download an image file with this code. I need to show download progress(<strong>downloaded bytes in percentage</strong>) on UI. How I can get download progress in this code? I searched for solution, but still can't manage to do it on my own.</p>
  
  <pre><code>Observable&lt;String&gt; downloadObservable = Observable.create(
                      sub -&gt; {
                          Request request = new Request.Builder()
                                  .url(media.getMediaUrl())
                                  .build();
                          Response response = null;
                          try {
                              response = http_client.newCall(request).execute();
                              if (response.isSuccessful()) {
                                  Log.d(TAG, "response.isSuccessful()");
                                  String mimeType = MimeTypeMap.getFileExtensionFromUrl(media.getMediaUrl());
                                  File file = new File(helper.getTmpFolder() + "/" + helper.generateUniqueName() + "test." + mimeType);
                                  BufferedSink sink = Okio.buffer(Okio.sink(file));
                                  sink.writeAll(response.body().source());
                                  sink.close();
                                  sub.onNext(response.toString());
                                  sub.onCompleted();
                              } else {
                                  sub.onError(new IOException());
                              }
                          } catch (IOException e) {
                              e.printStackTrace();
                          }
  
                      }
              );
  
              Subscriber&lt;String&gt; mySubscriber = new Subscriber&lt;String&gt;() {
                  @Override
                  public void onNext(String responseString) {
                      Log.d(TAG, "works: " + responseString);
                  }
              };
              downloadObservable
                      .subscribeOn(Schedulers.newThread())
                      .observeOn(AndroidSchedulers.mainThread())
                      .subscribe(mySubscriber);
  </code></pre>