コード例 #1
0
  /**
   * Start as a client to search WiFi and WiFi AP server.
   *
   * @param user which user do you want to search,just for direct ,in wifi &wifi-ap case,this param
   *     is must be null
   */
  public void searchServer(OnSearchListener searchListener) {
    // Close WiFi AP if AP is enabled.
    if (NetWorkUtil.isWifiApEnabled(mContext)) {
      NetWorkUtil.setWifiAPEnabled(mContext, null, false);
    }

    if (mWifiOrAPService != null) {
      mWifiOrAPService.startSearch(searchListener);
    } else {
      Intent intent = new Intent();
      intent.setClass(mContext, WifiOrAPService.class);
      bindService(intent, new WifiOrAPServiceConnection(false, null, searchListener));
    }
  }
コード例 #2
0
  private void startWifiServer(OnSearchListener searchListener) {
    // Unbind WiFi direct service.
    if (mDirectServiceConnection != null) {
      unbindService(mDirectServiceConnection);
    }

    // Close WiFi AP if AP is enabled.
    if (NetWorkUtil.isWifiApEnabled(mContext)) {
      NetWorkUtil.setWifiAPEnabled(mContext, null, false);
    }

    if (mWifiOrAPService != null) {
      mWifiOrAPService.startServer(SERVER_TYPE_WIFI, searchListener);
    } else {
      Intent intent = new Intent();
      intent.setClass(mContext, WifiOrAPService.class);
      bindService(intent, new WifiOrAPServiceConnection(true, SERVER_TYPE_WIFI, searchListener));
    }
  }
コード例 #3
0
  /**
   * Start as a client to search WiFi Direct server.
   *
   * @param searchListener
   * @param user
   */
  public void searchDirectServer(OnSearchListener searchListener, User user) {
    // TODO This method is not be called
    if (!NetWorkUtil.isWifiDirectSupport(mContext)) {
      Toast.makeText(mContext, "Not support wifi-direct", Toast.LENGTH_SHORT).show();
      return;
    }

    // Disable WiFi AP if WiFi AP is enabled.
    if (NetWorkUtil.isWifiApEnabled(mContext)) {
      NetWorkUtil.setWifiAPEnabled(mContext, null, false);
    }

    if (mDirectService != null) {
      mDirectService.startDirect(false, user, searchListener);
    } else {
      Intent intent = new Intent();
      intent.setClass(mContext, DirectService.class);
      bindService(intent, new DirectServiceConnection(false, user, searchListener));
    }
  }
コード例 #4
0
  private void startWifiDirectServer(User user, OnSearchListener searchListener) {
    if (!NetWorkUtil.isWifiDirectSupport(mContext)) {
      Toast.makeText(mContext, "Not support wifi-direct", Toast.LENGTH_SHORT).show();
      return;
    }

    // Unbind wifiOrAPService
    if (mWifiOrAPServiceConnection != null) {
      unbindService(mWifiOrAPServiceConnection);
    }

    // Disable WiFi AP if AP is enabled.
    if (NetWorkUtil.isWifiApEnabled(mContext)) {
      NetWorkUtil.setWifiAPEnabled(mContext, null, false);
    }

    if (mDirectService != null) {
      mDirectService.startDirect(true, user, searchListener);
    }

    Intent intent = new Intent();
    intent.setClass(mContext, DirectService.class);
    bindService(intent, new DirectServiceConnection(true, user, searchListener));
  }