public void onReceive(Context context, Intent intent) {
      String action = intent.getAction();
      Log.i("Jeffy", "action:" + action);
      if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) {
        int state =
            intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN);
        if (state == WifiManager.WIFI_STATE_ENABLED) {
          mWifiHandler.sendEmptyMessage(WIFI_MSG_SCAN);
        }
      }

      if (WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION.equals(action)) {
        boolean connected = intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED, false);
        if (connected && mReadyToTest) {
          Log.d("Jeffy===", "already connect to:" + mWifiManager.getConnectionInfo().getSSID());
          //					mHandler.sendEmptyMessageDelayed(MSG_FINISH_TEST, 1000);
          mWifiTestView.setStatus(TEST_STATUS.SUCCEED);
        }
      }
      if (WifiManager.SCAN_RESULTS_AVAILABLE_ACTION.equals(action)) {
        List<ScanResult> resultList = mWifiManager.getScanResults();
        if ((resultList != null) && (!resultList.isEmpty())) {
          mReadyToTest = true;
          Log.d("Jeffy===", " ____________-------- resultList.size() = " + resultList.size());
          mWifiTestView.setStatus(TEST_STATUS.SUCCEED);
        }
      }
    }
示例#2
0
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent == null) {
      return START_STICKY;
    }

    String action = intent.getAction();
    if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
      NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
      if (networkInfo.isConnected()) {
        WifiInfo wifiInfo = intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO);
        mListener.onNetworkChanged(wifiInfo);
      }
    } else if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) {
      int state = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN);
      switch (state) {
        case WifiManager.WIFI_STATE_DISABLED:
          mListener.onWiFiDisabled();
          break;
        case WifiManager.WIFI_STATE_ENABLED:
          mListener.onWiFiEnabled();
          break;
        default:
          break;
      }
    }
    return START_STICKY;
  }
  @Override
  public void doReceive(Intent intent) throws Exception {
    String action = intent.getAction();

    JSONObject json = new JSONObject();
    json.put(KEY_ACTION, action);

    if (WifiManager.SCAN_RESULTS_AVAILABLE_ACTION.equals(action)) {
      logScanResult(intent, json);
    } else if (WifiManager.RSSI_CHANGED_ACTION.equals(action)) {
      logRSSIChange(intent, json);
    } else if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) {
      logWifiState(intent, json);
    } else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
      logNetworkState(intent, json);
    }
    log(json);
  }
 private void handleEvent(Context context, Intent intent) {
   String action = intent.getAction();
   if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) {
     updateWifiState(
         intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN));
   } else if (WifiManager.SCAN_RESULTS_AVAILABLE_ACTION.equals(action)
       || WifiManager.CONFIGURED_NETWORKS_CHANGED_ACTION.equals(action)
       || WifiManager.LINK_CONFIGURATION_CHANGED_ACTION.equals(action)) {
     updateAccessPoints();
   } else if (WifiManager.SUPPLICANT_STATE_CHANGED_ACTION.equals(action)) {
     // Ignore supplicant state changes when network is connected
     // TODO: we should deprecate SUPPLICANT_STATE_CHANGED_ACTION and
     // introduce a broadcast that combines the supplicant and network
     // network state change events so the apps dont have to worry about
     // ignoring supplicant state change when network is connected
     // to get more fine grained information.
     SupplicantState state =
         (SupplicantState) intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE);
     if (!mConnected.get() && SupplicantState.isHandshakeState(state)) {
       updateConnectionState(WifiInfo.getDetailedStateOf(state));
     } else {
       // During a connect, we may have the supplicant
       // state change affect the detailed network state.
       // Make sure a lost connection is updated as well.
       updateConnectionState(null);
     }
   } else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
     NetworkInfo info = (NetworkInfo) intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
     mConnected.set(info.isConnected());
     changeNextButtonState(info.isConnected());
     updateAccessPoints();
     updateConnectionState(info.getDetailedState());
     if (mAutoFinishOnConnection && info.isConnected()) {
       Activity activity = getActivity();
       if (activity != null) {
         activity.setResult(Activity.RESULT_OK);
         activity.finish();
       }
       return;
     }
   } else if (WifiManager.RSSI_CHANGED_ACTION.equals(action)) {
     updateConnectionState(null);
   }
 }
示例#5
0
  public void onReceive(Context paramContext, Intent paramIntent) {

    // wifi开关
    if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(paramIntent.getAction())) {
      int wifiState = paramIntent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0);
      switch (wifiState) {
        case WifiManager.WIFI_STATE_DISABLED:
        case WifiManager.WIFI_STATE_ENABLED:
          mListener.wifiStatusChange();
          break;
      }
    }

    // 连接wifi
    else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(paramIntent.getAction())) {
      mNetworkInfo = paramIntent.getParcelableExtra("networkInfo");

      /** 当 DetailedState 变化为 CONNECTED 时,说明已连接成功,则通知Handler更新 可避免WifiapActivity里出现重复获取IP的问题 */
      if (mNetworkInfo.getDetailedState() == NetworkInfo.DetailedState.CONNECTED) {
        mListener.WifiConnected();
      }
    }
  }
  @Override
  public int onStartCommand(final Intent intent, final int flags, final int startId) {
    if (intent == null) {
      return START_STICKY;
    }

    String action = intent.getAction();
    if (CameraOverlay.DELETE_PREVIEW_ACTION.equals(action)) {
      if (mCameraOverlay.isShow()) {
        stopWebServer();
      }
      return START_STICKY;
    } else if ("android.intent.action.NEW_OUTGOING_CALL".equals(action)) {
      // Phone
      List<Event> events =
          EventManager.INSTANCE.getEventList(
              mServiceId,
              HostPhoneProfile.PROFILE_NAME,
              null,
              HostPhoneProfile.ATTRIBUTE_ON_CONNECT);

      for (int i = 0; i < events.size(); i++) {
        Event event = events.get(i);
        Intent mIntent = EventManager.createEventMessage(event);
        HostPhoneProfile.setAttribute(mIntent, HostPhoneProfile.ATTRIBUTE_ON_CONNECT);
        Bundle phoneStatus = new Bundle();
        HostPhoneProfile.setPhoneNumber(
            phoneStatus, intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER));
        HostPhoneProfile.setState(phoneStatus, CallState.START);
        HostPhoneProfile.setPhoneStatus(mIntent, phoneStatus);
        sendEvent(mIntent, event.getAccessToken());
      }
      return START_STICKY;
    } else if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)
        || WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
      // Wifi
      List<Event> events =
          EventManager.INSTANCE.getEventList(
              mServiceId,
              HostConnectProfile.PROFILE_NAME,
              null,
              HostConnectProfile.ATTRIBUTE_ON_WIFI_CHANGE);

      for (int i = 0; i < events.size(); i++) {
        Event event = events.get(i);
        Intent mIntent = EventManager.createEventMessage(event);
        HostConnectProfile.setAttribute(mIntent, HostConnectProfile.ATTRIBUTE_ON_WIFI_CHANGE);
        Bundle wifiConnecting = new Bundle();
        WifiManager wifiMgr = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
        HostConnectProfile.setEnable(wifiConnecting, wifiMgr.isWifiEnabled());
        HostConnectProfile.setConnectStatus(mIntent, wifiConnecting);
        sendEvent(mIntent, event.getAccessToken());
      }
      return START_STICKY;
    } else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
      List<Event> events =
          EventManager.INSTANCE.getEventList(
              mServiceId,
              HostConnectProfile.PROFILE_NAME,
              null,
              HostConnectProfile.ATTRIBUTE_ON_BLUETOOTH_CHANGE);

      for (int i = 0; i < events.size(); i++) {
        Event event = events.get(i);
        Intent mIntent = EventManager.createEventMessage(event);
        HostConnectProfile.setAttribute(mIntent, HostConnectProfile.ATTRIBUTE_ON_BLUETOOTH_CHANGE);
        Bundle bluetoothConnecting = new Bundle();
        BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        HostConnectProfile.setEnable(bluetoothConnecting, mBluetoothAdapter.isEnabled());
        HostConnectProfile.setConnectStatus(mIntent, bluetoothConnecting);
        sendEvent(mIntent, event.getAccessToken());
      }
      return START_STICKY;
    }
    return super.onStartCommand(intent, flags, startId);
  }