我正在创建具有NetworkType.CONNECTED约束的OneTimeWorkRequest,但是即使设备已连接到Internet,请求仍处于“已排队”状态
Constraints constraints = new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build();
OneTimeWorkRequest request = new OneTimeWorkRequest.Builder(SyncWorker.class)
.setConstraints(constraints)
.build();
WorkContinuation continuation = mWorkManager.beginUniqueWork("work",
ExistingWorkPolicy.KEEP, request);
continuation.enqueue();
答案 0 :(得分:0)
尝试一下?
Constraints constraints = new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build();
OneTimeWorkRequest request = new OneTimeWorkRequest.Builder(SyncWorker.class)
.setConstraints(constraints)
.build();
WorkManager.getInstance().enqueue(request);