|
|
@@ -11,20 +11,26 @@ import android.content.Intent;
|
|
|
import android.net.ConnectivityManager;
|
|
|
import android.net.NetworkInfo;
|
|
|
import android.net.wifi.WifiManager;
|
|
|
+import android.os.HandlerThread;
|
|
|
import android.util.Log;
|
|
|
+import android.os.Handler;
|
|
|
|
|
|
import com.google.android.gms.common.api.GoogleApiClient;
|
|
|
import com.ntels.kneet.v3.common.Constants;
|
|
|
+import com.ntels.kneet.v3.common.util.LogUtil;
|
|
|
import com.ntels.kneet.v3.common.util.Util;
|
|
|
+import com.ntels.kneet.v3.common.websocket.WebSocketService;
|
|
|
|
|
|
public class MdnsRegBroadcastRecevier extends BroadcastReceiver {
|
|
|
|
|
|
+ private static final String TAG = MdnsRegBroadcastRecevier.class.getSimpleName();
|
|
|
+
|
|
|
Context mContext;
|
|
|
Util util = new Util();
|
|
|
/** 위치 클라인 트 */
|
|
|
private GoogleApiClient mGoogleApiClient;
|
|
|
|
|
|
- @Override public void onReceive(Context context, Intent intent) {
|
|
|
+ @Override public void onReceive(final Context context, Intent intent) {
|
|
|
|
|
|
mContext = context;
|
|
|
|
|
|
@@ -46,6 +52,16 @@ public class MdnsRegBroadcastRecevier extends BroadcastReceiver {
|
|
|
break;
|
|
|
case WifiManager.WIFI_STATE_ENABLED:
|
|
|
Log.i("BOOTSVC", "WIFI STATE ENABLED");
|
|
|
+ /*new Handler().postDelayed(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ ComponentName cn = new ComponentName(context.getPackageName(), WebSocketService.class.getName());
|
|
|
+ ComponentName svcName = context.startService(new Intent().setComponent(cn));
|
|
|
+ if ( svcName == null ) {
|
|
|
+ Log.e(TAG, "Could not start WebSocketService " + cn.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, 5000);*/
|
|
|
break;
|
|
|
case WifiManager.WIFI_STATE_ENABLING:
|
|
|
Log.i("BOOTSVC", "WIFI STATE ENABLING");
|
|
|
@@ -57,6 +73,7 @@ public class MdnsRegBroadcastRecevier extends BroadcastReceiver {
|
|
|
} else if ( strAction.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION) ) {
|
|
|
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
NetworkInfo activeNetwork = manager.getActiveNetworkInfo();
|
|
|
+// boolean bDisconnected = false;
|
|
|
|
|
|
if ( null != activeNetwork ) {
|
|
|
if ( activeNetwork.getType() == ConnectivityManager.TYPE_WIFI ) {
|
|
|
@@ -72,10 +89,50 @@ public class MdnsRegBroadcastRecevier extends BroadcastReceiver {
|
|
|
}
|
|
|
} else if ( activeNetwork.getState() == NetworkInfo.State.DISCONNECTED ) {
|
|
|
Log.e("JINO TEST LOG", "JINO TEST LOG Network DISCONNECTED");
|
|
|
+// bDisconnected = true;
|
|
|
}
|
|
|
} else if ( activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE ) {
|
|
|
Log.e("JINO TEST LOG", "JINO TEST LOG Mobile CONNECTED");
|
|
|
}
|
|
|
+
|
|
|
+ /*if ( !bDisconnected ) {
|
|
|
+ ComponentName cn = new ComponentName(context.getPackageName(), WebSocketService.class.getName());
|
|
|
+ ComponentName svcName = context.startService(new Intent().setComponent(cn));
|
|
|
+ if ( svcName == null ) {
|
|
|
+ Log.e(TAG, "Could not start WebSocketService " + cn.toString());
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( strAction.equals(ConnectivityManager.CONNECTIVITY_ACTION) ) {
|
|
|
+ ConnectivityManager connectivityManager = (ConnectivityManager)
|
|
|
+ context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
+ boolean networkEnable = false;
|
|
|
+
|
|
|
+ if ( connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI) != null) {
|
|
|
+ if ( connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected() ) {
|
|
|
+ LogUtil.i(TAG, "WiFi network is connected!!");
|
|
|
+ networkEnable = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ( connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) != null) {
|
|
|
+ if ( connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected() ) {
|
|
|
+ LogUtil.i(TAG, "Mobile network is connected!!");
|
|
|
+ networkEnable = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ( networkEnable ) {
|
|
|
+ new Handler().postDelayed(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ ComponentName cn = new ComponentName(context.getPackageName(), WebSocketService.class.getName());
|
|
|
+ ComponentName svcName = context.startService(new Intent().setComponent(cn));
|
|
|
+ if ( svcName == null ) {
|
|
|
+ Log.e(TAG, "Could not start WebSocketService " + cn.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, 5000);
|
|
|
}
|
|
|
}
|
|
|
}
|