@NonNull @Override public Result doWork() { try { osmQuestChangesUpload.closeOpenChangesets(); } catch(OsmConnectionException e) { // wasn't able to connect to the server (i.e. connection timeout). Oh well, then, // never mind. Could also retry later with Result.retry() but the OSM API closes open // changesets after 1 hour anyway. } catch(OsmAuthorizationException e) { // the user may not be authorized yet (or not be authorized anymore) #283 // nothing we can do about here. He will have to reauthenticate when he next opens the app return Result.failure(); } return Result.success(); } }
@NonNull @Override public Result doWork() { Timber.d("Loading more event data from server"); Intent intent = new Intent(); intent.setAction("getMoreEvents"); intent.putExtra("numFollowing", 250); EpgSyncIntentService.enqueueWork(getApplicationContext(), intent); return Result.success(); } }
return Result.success(); } catch (Exception exception) { Log.e(TAG, "Error cleaning up", exception);
return Result.success(outputData); } catch (FileNotFoundException fileNotFoundException) { Log.e(TAG, "Failed to decode input stream", fileNotFoundException);
.putString(Constants.KEY_IMAGE_URI, imageUrl) .build(); return Result.success(outputData); } catch (Exception exception) { Log.e(TAG, "Unable to save image to Gallery", exception);
return ListenableWorker.Result.success(new Data.Builder() .putString(UnZIPWorker.KEY_ZIPFILE, downloadedFile.getAbsolutePath()) .build());
@NonNull @Override public Result doWork() { OkHttpClient client=new OkHttpClient(); Request request=new Request.Builder() .url(getInputData().getString(KEY_URL)) .build(); try (Response response=client.newCall(request).execute()) { File dir=getApplicationContext().getCacheDir(); File downloadedFile= new File(dir, getInputData().getString(KEY_FILENAME)); BufferedSink sink=Okio.buffer(Okio.sink(downloadedFile)); sink.writeAll(response.body().source()); sink.close(); } catch (IOException e) { Log.e(getClass().getSimpleName(), "Exception downloading file", e); return ListenableWorker.Result.failure(); } return ListenableWorker.Result.success(); } }
@NonNull @Override public Result doWork() { File downloadedFile=new File(getInputData().getString(KEY_ZIPFILE)); File dir=getApplicationContext().getCacheDir(); String resultDirData=getInputData().getString(KEY_RESULTDIR); File resultDir=new File(dir, resultDirData==null ? "results" : resultDirData); try { ZipUtils.unzip(downloadedFile, resultDir, 2048, 1024*1024*16); downloadedFile.delete(); } catch (Exception e) { Log.e(getClass().getSimpleName(), "Exception unZIPing file", e); return ListenableWorker.Result.failure(); } return ListenableWorker.Result.success(); } }
@NonNull @Override public Result doWork() { //在workRequest中传递来的data, Data data = getInputData(); String name = data.getString("name"); int age = data.getInt("age", 0); //do some work Log.i("test", "worker doWork() name: " + name + " age: " + age); //返回任务的结果数据, Data out = new Data.Builder() .putString("result", "哈哈哈,真的可以返回呀") .putInt("status", 200) .build(); return Result.success(out); } }
@NonNull @Override public Result doWork() { Timber.d("Loading channel icons from server"); EpgSyncIntentService.enqueueWork(getApplicationContext(), new Intent().setAction("loadChannelIcons")); return Result.success(); } }
@NonNull @Override public Result doWork() { if (MuzeiUpdateHelper.update(getApplicationContext(), this)) { return Result.success(); } else { return Result.failure(); } }
@NonNull @Override public Result doWork() { Timber.i("MQTTReconnectWorker Doing work (%s)",Thread.currentThread()); return messageProcessor.statefulCheckConnection() ? Result.success() : Result.retry(); } }
@NonNull @Override public Result doWork() { Timber.v("SendLocationPingWorker doing work"); locationProcessor.publishLocationMessage(MessageLocation.REPORT_TYPE_PING); return Result.success(); } }
@NonNull @Override public Result doWork() { Timber.v("MQTTKeepaliveWorker doing work"); return messageProcessor.statefulSendKeepalive() ? Result.success() : Result.retry(); } }