/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package my.home.lehome.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.util.Log;

import my.home.common.NetworkUtil;
import my.home.lehome.helper.LocalMsgHelper;
import my.home.lehome.helper.PushSDKManager;

/**
 * Created by legendmohe on 15/3/8.
 */
public class NetworkStateReceiver extends BroadcastReceiver {

    public static final String TAG = "NetworkStateReceiver";
    public static final String VALUE_INTENT_STOP_LOCAL_SERVER = "my.home.lehome.receiver.NetworkStateReceiver:stop";
    public static final String VALUE_INTENT_START_LOCAL_SERVER = "my.home.lehome.receiver.NetworkStateReceiver:start";

    @Override
    public void onReceive(Context context, Intent intent) {
        NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
        if (info != null) {
            Log.d(TAG, "NetworkInfo: " + info);
            if (info.isConnected()) {
                String ssid = NetworkUtil.getFormatSSID(context);
                String prefSSID = LocalMsgHelper.getLocalSSID(context);
                if (ssid.equals(prefSSID)) {
                    Log.d(TAG, "start " + "LocalMessageService " + LocalMsgHelper.startLocalMsgService(context));
                    if (LocalMsgHelper.startLocalMsgService(context)) {
                        Intent startIntent = new Intent(VALUE_INTENT_START_LOCAL_SERVER);
                        context.sendBroadcast(startIntent);
                        PushSDKManager.stopPushSDKService(context);
                    }
                } else {
                    Log.d(TAG, "stop " + "LocalMessageService");
                    PushSDKManager.startPushSDKService(context);
                    LocalMsgHelper.stopLocalMsgService(context);
                    Intent stopIntent = new Intent(VALUE_INTENT_STOP_LOCAL_SERVER);
                    context.sendBroadcast(stopIntent);
                }
            } else if (!info.isConnectedOrConnecting()) {
                Log.d(TAG, "stop " + "LocalMessageService");
                PushSDKManager.startPushSDKService(context);
                LocalMsgHelper.stopLocalMsgService(context);
                Intent stopIntent = new Intent(VALUE_INTENT_STOP_LOCAL_SERVER);
                context.sendBroadcast(stopIntent);
            }
        }
    }
}

@@ -750,17 +750,20 @@
 net.
-wifi.Wifi
+Connectivity
 Mana
@@ -1406,16 +1406,206 @@
         
+if (!intent.getAction().equals(%22android.net.conn.CONNECTIVITY_CHANGE%22)) %7B%0A            return;%0A        %7D%0A        if (intent.getExtras() == null) %7B%0A            return;%0A        %7D%0A        final 
 NetworkI
@@ -1645,12 +1645,20 @@
 tra(
-Wifi
+Connectivity
 Mana
@@ -1686,40 +1686,8 @@
 O);%0A
-        if (info != null) %7B%0A    
     
@@ -1734,24 +1734,36 @@
         
-    
 if (
+info != null && 
 info.isC
@@ -1772,24 +1772,91 @@
 nected()) %7B%0A
+            if (info.getType() == ConnectivityManager.TYPE_WIFI) %7B%0A
             
@@ -2821,32 +2821,32 @@
               %7D%0A
+
             %7D el
@@ -2851,45 +2851,8 @@
 else
- if (!info.isConnectedOrConnecting())
  %7B%0A 

Update NetworkStateReceiver.java