How to Detect network disconnection in Firebase Job dispatcher?

一世执手 提交于 2019-12-22 07:09:04

问题


In firebase Job dispatcher its possible to detect when we connect to a network, but how to detect when we disconnect from a network?

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

This will detect when connected to Unmetrered Network , i want to start a service whenever it is disconnected from all networks


回答1:


Using firebase dispatcher you can't check the disconnection (As far as I know), but you can use broadcast receivers for detecting connectivity change and call your job service inside them

refer this link for the usage of broadcast receivers

Broadcast receiver for checking internet connection in android app

in latest versions of android you need to dynamically register and unregister the Broadcast Receivers



来源:https://stackoverflow.com/questions/47044721/how-to-detect-network-disconnection-in-firebase-job-dispatcher

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!