Beispiel #1
0
	/**
	 * Function: 打开wifi功能<br>
	 * 
	 * @author ZYT DateTime 2014-5-14 上午11:01:11<br>
	 * @return true:打开成功;false:打开失败<br>
	 */
	public boolean openWifi() {
		boolean bRet = true;
		if (!mWifiManager.isWifiEnabled()) {
			bRet = mWifiManager.setWifiEnabled(true);
		}
		return bRet;
	}
  /* package */ void submit(WifiConfigController configController) {

    final WifiConfiguration config = configController.getConfig();

    if (config == null) {
      if (mSelectedAccessPoint != null && mSelectedAccessPoint.networkId != INVALID_NETWORK_ID) {
        mWifiManager.connect(mSelectedAccessPoint.networkId, mConnectListener);
      }
    } else if (config.networkId != INVALID_NETWORK_ID) {
      if (mSelectedAccessPoint != null) {
        mWifiManager.save(config, mSaveListener);
      }
    } else {
      if (configController.isEdit()) {
        mWifiManager.save(config, mSaveListener);
      } else {
        mWifiManager.connect(config, mConnectListener);
      }
    }

    if (mWifiManager.isWifiEnabled()) {
      mScanner.resume();
    }
    updateAccessPoints();
  }
  private void updateConnectionState(DetailedState state) {
    /* sticky broadcasts can call this when wifi is disabled */
    if (!mWifiManager.isWifiEnabled()) {
      mScanner.pause();
      return;
    }

    if (state == DetailedState.OBTAINING_IPADDR) {
      mScanner.pause();
    } else {
      mScanner.resume();
    }

    mLastInfo = mWifiManager.getConnectionInfo();
    if (state != null) {
      mLastState = state;
    }

    for (int i = getPreferenceScreen().getPreferenceCount() - 1; i >= 0; --i) {
      // Maybe there's a WifiConfigPreference
      Preference preference = getPreferenceScreen().getPreference(i);
      if (preference instanceof AccessPoint) {
        final AccessPoint accessPoint = (AccessPoint) preference;
        accessPoint.update(mLastInfo, mLastState);
      }
    }
  }
Beispiel #4
0
 public void startScan() {
   mWifiManager.startScan();
   // �õ�ɨ����
   mWifiList = mWifiManager.getScanResults();
   // �õ����úõ���������
   mWifiConfiguration = mWifiManager.getConfiguredNetworks();
 }
  @Override
  void initValues() {
    mContext = Add_DeviceActivity.this;
    mBackClassName = getBackClassName();
    mNowClassName = getNowClassName();

    mWifiManger = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    List<WifiConfiguration> listWifiConfiguration = mWifiManger.getConfiguredNetworks();

    //        Log.e("mWifiManger.isWifiEnabled()", "wifiEnabled:" + mWifiManger.isWifiEnabled());
    if (!mWifiManger.isWifiEnabled()) {
      Toast.makeText(this, getString(R.string.open_wifi), Toast.LENGTH_SHORT).show();
      startActivity(new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS));
      overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
    } else {
      for (int i = 0; i < listWifiConfiguration.size(); i++) {
        if (mWifiManger.getConnectionInfo().getSSID().equals(listWifiConfiguration.get(i).SSID)) {
          mOriginWifiConfig = listWifiConfiguration.get(i);
        }
      }
    }

    mWifiScanReceiver = new WifiScanReceiver();
    mWifiChangeReceiver = new WifiChangeReceiver();
  }
  /**
   * @author Arthur Carvalho
   * @since 09/09/2011
   * @param context
   * @return o IMEI do aparelho
   */
  public static String getEnderecoMac(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    String enderecoMac = wifiInfo.getMacAddress();

    return enderecoMac.replace(":", "");
  }
  @Override
  public boolean execute(String action, JSONArray args, final CallbackContext callbackContext)
      throws JSONException {
    WifiManager wifiMgr =
        (WifiManager) cordova.getActivity().getSystemService(Context.WIFI_SERVICE);
    DhcpInfo ipConfig = wifiMgr.getDhcpInfo();

    if (IpUtils.toIpv4(ipConfig.ipAddress).compareTo("0.0.0.0") != 0) {
      netConfig.put("ipAddress", IpUtils.toIpv4(ipConfig.ipAddress));
    }
    netConfig.put("ipAddress", IpUtils.toIpv4(ipConfig.ipAddress));
    netConfig.put("macAddress", wifiMgr.getConnectionInfo().getMacAddress());
    netConfig.put("netmask", IpUtils.toIpv4(ipConfig.netmask));
    netConfig.put("gateway", IpUtils.toIpv4(ipConfig.gateway));
    netConfig.put("dns1", IpUtils.toIpv4(ipConfig.dns1));
    netConfig.put("dns2", IpUtils.toIpv4(ipConfig.dns1));

    if (netConfig != null) {
      callbackContext.success(netConfig);
      return true;
    } else {
      callbackContext.error("Operation failed");

      return false;
    }
  }
Beispiel #8
0
  private void loadNetworkList() {
    WifiManager wm = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
    List<WifiConfiguration> wcs = wm.getConfiguredNetworks();
    String[] ssidEntries = null;
    int n = 3;

    if (wcs == null) {
      ssidEntries = new String[n];

      ssidEntries[0] = Constraints.WIFI_AND_3G;
      ssidEntries[1] = Constraints.ONLY_WIFI;
      ssidEntries[2] = Constraints.ONLY_3G;
    } else {
      ssidEntries = new String[wcs.size() + n];

      ssidEntries[0] = Constraints.WIFI_AND_3G;
      ssidEntries[1] = Constraints.ONLY_WIFI;
      ssidEntries[2] = Constraints.ONLY_3G;

      for (WifiConfiguration wc : wcs) {
        if (wc != null && wc.SSID != null) {
          ssidEntries[n++] = wc.SSID.replace("\"", "");
        } else {
          ssidEntries[n++] = "unknown";
        }
      }
    }
    ssidList.setEntries(ssidEntries);
    ssidList.setEntryValues(ssidEntries);
  }
  public boolean connectToAccessPoint(WifiScanResult ap) {

    if (ap == null) return false;

    setStatus("Connecting to Access Point: " + ap.BSSID);
    WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);

    // disconnect from any current APs
    wm.disconnect();
    // try {
    //	Thread.sleep(500);
    // } catch (InterruptedException ie) {
    //	//do nothing
    // }
    currentResult.connected_bssid = ap.BSSID;
    currentResult.attempted_bssids.add(ap.BSSID);
    boolean ret = connectToXfinityWifiNetwork(ap.BSSID);

    // unable to connect to xfinity wifi
    if (ret == false) {
      // Log an unsuccessful connection
      // TODO
      currentResult.connection_established = false;
      return false;
    }

    currentResult.connection_established = true;

    return true;
  }
  private void initList() {
    wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    if (wifi.isWifiEnabled() == false) {
      Toast.makeText(
              getApplicationContext(), "Wifi is disabled. It is being enabled.", Toast.LENGTH_LONG)
          .show();
      wifi.setWifiEnabled(true);
    }

    setWifiStatus(true);
    wifi.startScan();

    try {
      size = size - 1;
      if (size > 0) {
        scanning_textView.setVisibility(View.GONE);
        wifiListview.setVisibility(View.VISIBLE);
        setWifiList();
      } else {
        scanning_textView.setVisibility(View.VISIBLE);
        wifiListview.setVisibility(View.GONE);
      }
      while (size >= 0) {
        size--;

        listAdapter.notifyDataSetChanged();
      }
    } catch (Exception e) {
    }
  }
 public boolean isWifiAvailable() {
   WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
   if (wifiManager != null && wifiManager.isWifiEnabled()) {
     return true;
   }
   return false;
 }
  private void setWifiStatus(boolean onOff) {
    wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    if (onOff) {
      if (wifi.isWifiEnabled() == false) {
        Toast.makeText(
                getApplicationContext(),
                "Wifi is disabled. It is being enabled.",
                Toast.LENGTH_LONG)
            .show();
      }
      wifi.setWifiEnabled(true);
      scanning_textView.setVisibility(View.GONE);
      wifiListview.setVisibility(View.VISIBLE);
      wifiOnOff.setChecked(true);
      wifiOnOff.setBackgroundColor(getResources().getColor(R.color.greenEnd));
    } else {

      Toast.makeText(getApplicationContext(), "Wifi is disabled.", Toast.LENGTH_LONG).show();
      wifi.setWifiEnabled(false);
      wifiOnOff.setChecked(false);
      wifiOnOff.setBackgroundColor(getResources().getColor(R.color.lightGrey));
      scanning_textView.setVisibility(View.GONE);
      wifiListview.setVisibility(View.GONE);
    }
  }
Beispiel #13
0
 public void onDestroy() {
   super.onDestroy();
   WifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE);
   final String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
   deleteMarqueurBDD(ip); // Delete tout les marqueurs de la session
   mapView.destroyAll();
 }
  /**
   * Observes WiFi Access Points. Returns fresh list of Access Points whenever WiFi signal strength
   * changes.
   *
   * @param context Context of the activity or an application
   * @return RxJava Observable with list of WiFi scan results
   */
  public Observable<List<ScanResult>> observeWifiAccessPoints(final Context context) {
    final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    wifiManager.startScan(); // without starting scan, we may never receive any scan results

    final IntentFilter filter = new IntentFilter();
    filter.addAction(WifiManager.RSSI_CHANGED_ACTION);
    filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);

    return Observable.create(
        new Observable.OnSubscribe<List<ScanResult>>() {
          @Override
          public void call(final Subscriber<? super List<ScanResult>> subscriber) {
            final BroadcastReceiver receiver =
                new BroadcastReceiver() {
                  @Override
                  public void onReceive(Context context, Intent intent) {
                    wifiManager
                        .startScan(); // we need to start scan again to get fresh results ASAP
                    subscriber.onNext(wifiManager.getScanResults());
                  }
                };

            context.registerReceiver(receiver, filter);

            subscriber.add(
                unsubscribeInUiThread(
                    new Action0() {
                      @Override
                      public void call() {
                        context.unregisterReceiver(receiver);
                      }
                    }));
          }
        });
  }
  public void updateTimer() {

    //
    // Check if the time since the last scan has been 60 secs
    // If Not just reset the time since last scan to 60 secs
    // else
    // Request a scan
    //
    try {
      currentTime = System.currentTimeMillis();
      long timeSinceLastScan = currentTime - lastScanTime;
      if (timeSinceLastScan >= 60000) {
        if (!wifiMgr.isWifiEnabled() || !wifiMgr.startScan()) {
          Log.v(TAG, "startScan() returned error");
          lastScanTime = System.currentTimeMillis();
        }
        tHandler.postDelayed(tUpdateTimerRunnable, 60000);
      } else {
        tHandler.postDelayed(tUpdateTimerRunnable, 60000 - timeSinceLastScan);
      }
    } catch (SecurityException se) {
      Log.e(
          TAG,
          "Possible missing permissions needed to run ICE over AllJoyn. Discovery over ICE in AllJoyn may not work due to this");
      se.printStackTrace();
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
    WifiInfo wifIinfo = wifiManager.getConnectionInfo();
    int address = wifIinfo.getIpAddress();
    String ipAddressStr =
        ((address >> 0) & 0xFF)
            + "."
            + ((address >> 8) & 0xFF)
            + "."
            + ((address >> 16) & 0xFF)
            + "."
            + ((address >> 24) & 0xFF);
    TextView tv = (TextView) findViewById(R.id.tv1);
    tv.setText(ipAddressStr);

    if (runner == null) {
      runner = new Thread(this);
      runner.start();
    }
    Toast.makeText(this, "スレッドスタート", Toast.LENGTH_SHORT).show();
  }
  @Override
  protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.downloader);

    _downloadingText = (TextView) findViewById(R.id.downloadDownloadingText);
    _infoText = (TextView) findViewById(R.id.downloadInfoText);
    _progressBar = (ProgressBar) findViewById(R.id.downloadProgressBar);
    _progressText = (TextView) findViewById(R.id.downloadProgressText);

    _progressBar.setMax(100);

    _handler = new DownloadMessageHandler(this);

    final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    _wifiLock =
        wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, DownloadActivity.class.getName());

    scheduleDownloadingTextAnimation();

    final Intent intent = getIntent();
    final EpisodeModel episode =
        (EpisodeModel) intent.getSerializableExtra(getString(R.string.key_episode));

    final ProgrammeModel programme = episode.getProgramme();
    final String programmeName = programme.getName();
    final String name = episode.getName();
    final Date date = episode.getDate();
    final String dateStr = DATE_FORMAT.format(date);
    setTitle(getString(R.string.download_title) + " - " + programmeName);
    _infoText.setText(programmeName + " " + dateStr + "\n" + name);

    new Downloader(this, episode, 10, _wifiLock, _handler).start();
  }
Beispiel #18
0
 public static String getMacAddress(Context aContext) {
   String result = null;
   WifiManager wifiManager = (WifiManager) aContext.getSystemService(Context.WIFI_SERVICE);
   WifiInfo wifiInfo = wifiManager.getConnectionInfo();
   result = wifiInfo.getMacAddress();
   return result;
 }
  @Override
  public void onClick(View v) {
    switch (v.getId()) {
      case R.id.GetBatteryMSG:
        // 起动查询电量
        // 注册广播接受者java代码
        IntentFilter intentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
        // 创建广播接受者对象
        BatteryReceiver batteryReceiver = new BatteryReceiver();

        // 注册receiver
        registerReceiver(batteryReceiver, intentFilter);
        break;
      case R.id.ScanWifi:
        WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        List<ScanResult> wifiList = wm.getScanResults();
        for (int i = 0; i < wifiList.size(); i++) {
          ScanResult result = wifiList.get(i);
          Log.d(
              "wifi===========",
              "level=" + result.level + "ssid=" + result.SSID + "bssid=" + result.BSSID);
        }
        playBeepSoundAndVibrate();
        break;
      default:
        break;
    }
  }
 /**
  * 获取本地Ip地址
  *
  * @param context
  * @return
  */
 public static String getLocalIpAddress(Context context) {
   WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
   WifiInfo wifiInfo = wifiManager.getConnectionInfo();
   if (wifiInfo != null && wifiInfo.getIpAddress() != 0) {
     return android.text.format.Formatter.formatIpAddress(wifiInfo.getIpAddress());
   } else {
     try {
       Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
       while (en.hasMoreElements()) {
         NetworkInterface intf = en.nextElement();
         Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses();
         while (enumIpAddr.hasMoreElements()) {
           InetAddress inetAddress = enumIpAddr.nextElement();
           if (!inetAddress.isLoopbackAddress()
               && inetAddress.getHostAddress().indexOf(":") == -1) {
             String ipAddress = inetAddress.getHostAddress();
             if (!TextUtils.isEmpty(ipAddress) && !ipAddress.contains(":")) {
               return ipAddress;
             }
           }
         }
       }
     } catch (SocketException e) {
       e.printStackTrace();
     }
   }
   return null;
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_flight_controls);

    WifiManager wifiManager =
        (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    wifiManager.setWifiEnabled(false);

    if (getIntent().getExtras() != null) {
      mDevice = getIntent().getExtras().getParcelable("btdevice");
      controls_list = getIntent().getExtras().getBooleanArray("controls_lst");
    }

    if (controls_list != null) {
      if (!controls_list[0]) {
        findViewById(R.id.frame_flight_takeoff).setVisibility(RelativeLayout.GONE);
        findViewById(R.id.frame_controls).setVisibility(TableLayout.VISIBLE);
      }

      if (!controls_list[3])
        findViewById(R.id.panel_flight_stop).setVisibility(LinearLayout.INVISIBLE);
    }

    initBT();
    initVars();
  }
  private void toggleWifi() {
    if (mWifiManager == null) {
      mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    }

    int state = mWifiManager.getWifiState();
    int apState = mWifiManager.getWifiApState();

    if (state == WifiManager.WIFI_STATE_ENABLING || state == WifiManager.WIFI_STATE_DISABLING) {
      return;
    }
    if (apState == WifiManager.WIFI_AP_STATE_ENABLING
        || apState == WifiManager.WIFI_AP_STATE_DISABLING) {
      return;
    }

    if (state == WifiManager.WIFI_STATE_ENABLED || apState == WifiManager.WIFI_AP_STATE_ENABLED) {
      mWifiManager.setWifiEnabled(false);
      mWifiManager.setWifiApEnabled(null, false);
      notifyKey(ASUSDEC_WIFI, ASUSDEC_STATUS_OFF);

    } else if (state == WifiManager.WIFI_STATE_DISABLED
        && apState == WifiManager.WIFI_AP_STATE_DISABLED) {
      mWifiManager.setWifiEnabled(true);
      notifyKey(ASUSDEC_WIFI, ASUSDEC_STATUS_ON);
    }
  }
Beispiel #23
0
  /**
   * Configure a network, and connect to it.
   *
   * @param wifiMgr
   * @param scanResult
   * @param password Password for secure network or is ignored.
   * @return
   */
  public boolean connectToNewNetwork(
      ScanResult scanResult, String password, int numOpenNetworksKept) {
    final String security = ConfigSec.getScanResultSecurity(scanResult);

    if (ConfigSec.isOpenNetwork(security)) {
      checkForExcessOpenNetworkAndSave(numOpenNetworksKept);
    }

    WifiConfiguration config = new WifiConfiguration();
    config.SSID = convertToQuotedString(scanResult.SSID);
    config.BSSID = scanResult.BSSID;
    ConfigSec.setupSecurity(config, security, password);

    int id = -1;
    try {
      id = mWifiManager.addNetwork(config);
    } catch (NullPointerException e) {
      Log.e(TAG, "Weird!! Really!! What's wrong??", e);
    }
    if (id == -1) {
      return false;
    }

    if (!mWifiManager.saveConfiguration()) {
      return false;
    }

    config = getWifiConfiguration(config, security);
    if (config == null) {
      return false;
    }

    return connectToConfiguredNetwork(config, true);
  }
Beispiel #24
0
 @Override
 public void run() {
   ConnectivityManager connMgr =
       (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
   NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
   if ((networkInfo == null)
       || (!networkInfo.isConnected())
       || (networkInfo.getType() != ConnectivityManager.TYPE_WIFI)) {
     bundle.putInt(
         Constants.SERVER_THREAD_STATUS, Constants.SERVER_THREAD_STATUS_WIFI_NOT_CONNECTED);
     msg.setData(bundle);
     MainActivity.this.serverThreadMessageHandler.sendMessage(msg);
     return;
   }
   WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
   WifiInfo wifiInfo = wifiManager.getConnectionInfo();
   int ipAddress = wifiInfo.getIpAddress();
   String ip =
       (ipAddress & 0xff)
           + "."
           + (ipAddress >> 8 & 0xff)
           + "."
           + (ipAddress >> 16 & 0xff)
           + "."
           + (ipAddress >> 24 & 0xff);
   try {
     serverSocket = new ServerSocket(Constants.SERVER_PORT);
     bundle.putInt(Constants.SERVER_THREAD_STATUS, Constants.SERVER_THREAD_STATUS_LISTENING);
     bundle.putString(Constants.IP_ADDRESS, ip);
     msg.setData(bundle);
     MainActivity.this.serverThreadMessageHandler.sendMessage(msg);
   } catch (Exception e) {
     bundle.putInt(Constants.SERVER_THREAD_STATUS, Constants.SERVER_THREAD_STATUS_INIT_FAILED);
     msg.setData(bundle);
     MainActivity.this.serverThreadMessageHandler.sendMessage(msg);
     return;
   }
   Socket clientSocket;
   while (true) {
     try {
       clientSocket = serverSocket.accept();
       String hostAddress = clientSocket.getInetAddress().getHostAddress();
       boolean inClients = false;
       for (Client client : clients)
         if (client.host.equals(hostAddress)) {
           inClients = true;
           break;
         }
       if (!inClients) {
         Client newClient = new Client(hostAddress);
         clients.add(newClient);
         newClient.connect();
       }
       Server server = new Server(clientSocket, hostAddress);
       servers.add(server);
       server.start();
     } catch (Exception e) {
     }
   }
 }
Beispiel #25
0
  public static String getDeviceID(Context context) {

    /*
     * The drawback of this approach is, if the service was opened when
     * the device is in airplane mode. MobiSens will think this is a
     * different phone.
     */
    if (globalDeviceID != null) {
      return globalDeviceID;
    }

    TelephonyManager telManager =
        (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    String deviceID = telManager.getDeviceId();

    if (deviceID == null) {
      WifiManager wifiMan = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
      WifiInfo wifiInf = wifiMan.getConnectionInfo();
      deviceID = wifiInf.getMacAddress();
    }

    globalDeviceID = deviceID;
    return globalDeviceID;
  }
  private List<ScanResult> getWifiExceptPionList() {
    List<ScanResult> scanNoPionResult = new ArrayList<>();
    WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    List<ScanResult> scanResult = wifiManager.getScanResults();

    Iterator<ScanResult> iterator = scanResult.iterator();

    // delete duplicate wifi
    List<String> ssidList = new ArrayList<>();
    while (iterator.hasNext()) {
      ScanResult s = iterator.next();
      if (ssidList.contains(s.SSID)) {
        iterator.remove();
      } else {
        ssidList.add(s.SSID);
      }
    }

    // delete pion wifi
    for (ScanResult s : scanResult) {
      if (s.SSID.contains(PION_WIFI_PREFIX) || s.SSID.contains(WIO_WIFI_PREFIX)) {
        continue;
      }
      scanNoPionResult.add(s);
    }

    return scanNoPionResult;
  }
 @Override
 public boolean onContextItemSelected(MenuItem item) {
   if (mSelectedAccessPoint == null) {
     return super.onContextItemSelected(item);
   }
   switch (item.getItemId()) {
     case MENU_ID_CONNECT:
       {
         if (mSelectedAccessPoint.networkId != INVALID_NETWORK_ID) {
           mWifiManager.connect(mSelectedAccessPoint.networkId, mConnectListener);
         } else if (mSelectedAccessPoint.security == AccessPoint.SECURITY_NONE) {
           /** Bypass dialog for unsecured networks */
           mSelectedAccessPoint.generateOpenNetworkConfig();
           mWifiManager.connect(mSelectedAccessPoint.getConfig(), mConnectListener);
         } else {
           showDialog(mSelectedAccessPoint, true);
         }
         return true;
       }
     case MENU_ID_FORGET:
       {
         mWifiManager.forget(mSelectedAccessPoint.networkId, mForgetListener);
         return true;
       }
     case MENU_ID_MODIFY:
       {
         showDialog(mSelectedAccessPoint, true);
         return true;
       }
   }
   return super.onContextItemSelected(item);
 }
Beispiel #28
0
 public static void enableMulticast() {
   WifiManager wifi = (WifiManager) ofActivity.getSystemService(Context.WIFI_SERVICE);
   if (wifi != null) {
     mcLock = wifi.createMulticastLock("mylock");
     mcLock.acquire();
   }
 }
  private void updateWifiState(int state) {
    Activity activity = getActivity();
    if (activity != null) {
      activity.invalidateOptionsMenu();
    }

    switch (state) {
      case WifiManager.WIFI_STATE_ENABLED:
        // this function only returns valid results in enabled state
        mIbssSupported = mWifiManager.isIbssSupported();
        mSupportedChannels = mWifiManager.getSupportedChannels();

        mScanner.resume();
        return; // not break, to avoid the call to pause() below

      case WifiManager.WIFI_STATE_ENABLING:
        addMessagePreference(R.string.wifi_starting);
        break;

      case WifiManager.WIFI_STATE_DISABLED:
        setOffMessage();
        break;
    }

    mLastInfo = null;
    mLastState = null;
    mScanner.pause();
  }
Beispiel #30
0
  public static boolean setWifiHostpotEnabled(
      final Context pContext, final WifiConfiguration pWifiConfiguration, final boolean pEnabled)
      throws WifiUtilsException {
    final WifiManager wifiManager = WifiUtils.getWifiManager(pContext);

    try {
      if (pEnabled) {
        WifiUtils.setWifiEnabled(pContext, false);
      }

      final Method WifiManager_setWifiApEnabled =
          wifiManager
              .getClass()
              .getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
      if (WifiManager_setWifiApEnabled == null) {
        throw new WifiUtilsException(
            new MethodNotFoundException(
                WifiManager.class.getSimpleName()
                    + ".setWifiApEnabled("
                    + WifiConfiguration.class.getSimpleName()
                    + ", "
                    + boolean.class.getSimpleName()
                    + ")"));
      } else {
        final boolean result =
            (Boolean)
                WifiManager_setWifiApEnabled.invoke(wifiManager, pWifiConfiguration, pEnabled);
        return result;
      }
    } catch (final Throwable t) {
      throw new WifiUtilsException(t);
    }
  }