Android Machine is not on the network Android Machine is not on the network android android

Android Machine is not on the network


Use Service which start service and stop service when network would be change or when stop network.Also check same port which is using release first and after that use that port.Do whatever task you want in onStartCommand().

@Overridepublic void onReceive(Context context, Intent intent) {  Date now = new Date();  Long time = now.getTime();  String action = intent.getAction();  NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);  if (networkInfo.getState() == NetworkInfo.State.CONNECTED) {    boolean check = isMyServiceRunning(context,    service.getName());    if (check) {      Intent i = new Intent(sqlitewraper.context,service.class);      stopService(i);    }    else{      Intent i = new Intent(sqlitewraper.context,service.class);      startservice(i);    }  }  if (networkInfo.getState() == NetworkInfo.State.DISCONNECTED) {    boolean check = isMyServiceRunning(context,    service.getName());    if (check) {      Intent i = new Intent(sqlitewraper.context,service.class);      stopService(i);    }  }  private boolean isMyServiceRunning(Context context, String Myservice) {    ActivityManager manager = (ActivityManager) context    .getSystemService(Context.ACTIVITY_SERVICE);    for (RunningServiceInfo service : manager    .getRunningServices(Integer.MAX_VALUE)) {      if (Myservice.equals(service.service.getClassName())) {        return true;      }    }    return false;  }}