在 firebase Job dispatcher 中,可以检测我们何时连接到网络,但是如何检测我们何时断开网络连接?
Job myJob = dispatcher.newJobBuilder()
.setService(MyJobService.class)
.setTag("my-unique-tag")
.setConstraints(
// only run on an unmetered network
Constraint.ON_UNMETERED_NETWORK,
// only run when the device is charging
Constraint.DEVICE_CHARGING
)
.build();
dispatcher.mustSchedule(myJob);
这将检测何时连接到未计量网络,我想在与所有网络断开连接时启动服务