Java Code Examples for android.net.NetworkInfo.State#DISCONNECTED

The following examples show how to use android.net.NetworkInfo.State#DISCONNECTED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MPushReceiver.java    From mpush-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (ACTION_HEALTH_CHECK.equals(action)) {//处理心跳
        if (MPush.I.hasStarted()) {
            if (MPush.I.client.isRunning()) {
                if (MPush.I.client.healthCheck()) {
                    startAlarm(context, delay);
                }
            }
        }
    } else if (CONNECTIVITY_ACTION.equals(action)) {//处理网络变化
        if (hasNetwork(context)) {
            if (STATE != State.CONNECTED) {
                STATE = State.CONNECTED;
                if (MPush.I.hasStarted()) {
                    MPush.I.onNetStateChange(true);

                    //MPush.I.resumePush();
                } else {
                    MPush.I.checkInit(context).startPush();
                }
            }
        } else {
            if (STATE != State.DISCONNECTED) {
                STATE = State.DISCONNECTED;
                MPush.I.onNetStateChange(false);

                //MPush.I.pausePush();
                //cancelAlarm(context);//防止特殊场景下alarm没被取消
            }
        }
    } else if (ACTION_NOTIFY_CANCEL.equals(action)) {//处理通知取消
        Notifications.I.clean(intent);
    }
}