8

我正在使用 NetworkType.CONNECTED 约束创建 OneTimeWorkRequest,但即使设备连接到互联网,请求仍处于 ENQUEUED 状态

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();
4

1 回答 1

0

尝试这个?

Constraints constraints = new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build();

OneTimeWorkRequest request = new OneTimeWorkRequest.Builder(SyncWorker.class)
            .setConstraints(constraints)
            .build();

WorkManager.getInstance().enqueue(request);
于 2018-07-03T07:37:56.587 回答