2

I'm using Android WorkManager version 1.0.0-beta-01 to upload some files to the server. Now I want to send back upload progress as it goes on (and not just the final result) to the caller.

class UploadWorker @Inject constructor(context: Application,
                                   parameters: WorkerParameters,
                                   private val uploadService: UploadService)
: RxWorker(context, parameters) {
    @SuppressLint("CheckResult")
    override fun createWork(): Single<Result> {
        val filePath = inputData.getString(FILE_PATH)

        //logic for sending files goes here where I want to send back the progress

        return Single.just(Result.success())
    }
}

I can achieve this by having a singleton object somewhere in my app with LiveData in it, then update the LiveData from my Work and listen to it in the caller but it doesn't seem like a good solution! Is there any better way to achieve this?

Alireza Ahmadi
  • 5,122
  • 7
  • 40
  • 67
  • Possible duplicate of [Showing detailed progress for running WorkManager workers](https://stackoverflow.com/questions/50542223/showing-detailed-progress-for-running-workmanager-workers) – Paulo Pereira Sep 24 '19 at 13:19
  • Progress report is now available natively. [See this answer](https://stackoverflow.com/a/58081057/5214620) – Paulo Pereira Sep 24 '19 at 13:19

0 Answers0