Java 类android.net.wifi.WifiConfiguration 实例源码

项目:GravityBox    文件:WifiPriorityActivity.java   
public void drop(int from, int to) {
    if (from == to) return;

    // Sort networks by user selection
    List<WifiNetwork> networks = mAdapter.getNetworks();
    WifiNetwork o = networks.remove(from);
    networks.add(to, o);

    // Set the new priorities of the networks
    int cc = networks.size();
    ArrayList<WifiConfiguration> configList = new ArrayList<>();
    for (int i = 0; i < cc; i++) {
        WifiNetwork network = networks.get(i);
        network.config.priority = cc - i;
        configList.add(network.config);
    }

    mNetworksListView.invalidateViews();

    Intent intent = new Intent(ModHwKeys.ACTION_UPDATE_WIFI_CONFIG);
    intent.putParcelableArrayListExtra(ModHwKeys.EXTRA_WIFI_CONFIG_LIST, configList);
    intent.putExtra("receiver", mReceiver);
    WifiPriorityActivity.this.sendBroadcast(intent);
}
项目:keepass2android    文件:WifiConfigManager.java   
/**
 * Update the network: either create a new network or modify an existing network
 * @param config the new network configuration
 */
private static void updateNetwork(WifiManager wifiManager, WifiConfiguration config) {
  Integer foundNetworkID = findNetworkInExistingConfig(wifiManager, config.SSID);
  if (foundNetworkID != null) {
    Log.i(TAG, "Removing old configuration for network " + config.SSID);
    wifiManager.removeNetwork(foundNetworkID);
    wifiManager.saveConfiguration();
  }
  int networkId = wifiManager.addNetwork(config);
  if (networkId >= 0) {
    // Try to disable the current network and start a new one.
    if (wifiManager.enableNetwork(networkId, true)) {
      Log.i(TAG, "Associating to network " + config.SSID);
      wifiManager.saveConfiguration();
    } else {
      Log.w(TAG, "Failed to enable network " + config.SSID);
    }
  } else {
    Log.w(TAG, "Unable to add network " + config.SSID);
  }
}
项目:WifiUtils    文件:ConfigSecurities.java   
@Nullable
static WifiConfiguration getWifiConfiguration(@NonNull final WifiManager wifiMgr, @NonNull final ScanResult scanResult) {
    if (scanResult.BSSID == null || scanResult.SSID == null || scanResult.SSID.isEmpty() || scanResult.BSSID.isEmpty())
        return null;
    final String ssid = convertToQuotedString(scanResult.SSID);
    final String bssid = scanResult.BSSID;
    final String security = getSecurity(scanResult);

    final List<WifiConfiguration> configurations = wifiMgr.getConfiguredNetworks();
    if (configurations == null)
        return null;

    for (final WifiConfiguration config : configurations) {
        if (bssid.equals(config.BSSID) || ssid.equals(config.SSID)) {
            final String configSecurity = getSecurity(config);
            if (Objects.equals(security, configSecurity))
                return config;
        }
    }
    return null;
}
项目:TaipeiTechRefined    文件:WifiUtility.java   
public static boolean connectToNtutcc(Context context) {
    try {
        WifiManager wifiManager = (WifiManager) context
                .getSystemService(Context.WIFI_SERVICE);
        WifiConfiguration conf = new WifiConfiguration();
        conf.SSID = "\"" + NTUTCC_SSID + "\"";
        conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
        wifiManager.addNetwork(conf);
        List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
        for (WifiConfiguration i : list) {
            if (i.SSID != null && i.SSID.equals("\"" + NTUTCC_SSID + "\"")) {
                wifiManager.disconnect();
                wifiManager.enableNetwork(i.networkId, true);
                wifiManager.reconnect();
                return true;
            }
        }
    } catch (Exception e) {
    }
    return false;
}
项目:WifiUtils    文件:ConnectorUtils.java   
@SuppressWarnings("UnusedReturnValue")
private static boolean checkForExcessOpenNetworkAndSave(@NonNull final ContentResolver resolver, @NonNull final WifiManager wifiMgr) {
    final List<WifiConfiguration> configurations = wifiMgr.getConfiguredNetworks();
    sortByPriority(configurations);

    boolean modified = false;
    int tempCount = 0;
    final int numOpenNetworksKept = Build.VERSION.SDK_INT >= 17
            ? Settings.Secure.getInt(resolver, Settings.Global.WIFI_NUM_OPEN_NETWORKS_KEPT, 10)
            : Settings.Secure.getInt(resolver, Settings.Secure.WIFI_NUM_OPEN_NETWORKS_KEPT, 10);

    for (int i = configurations.size() - 1; i >= 0; i--) {
        final WifiConfiguration config = configurations.get(i);
        if (Objects.equals(ConfigSecurities.SECURITY_NONE, ConfigSecurities.getSecurity(config))) {
            tempCount++;
            if (tempCount >= numOpenNetworksKept) {
                modified = true;
                wifiMgr.removeNetwork(config.networkId);
            }
        }
    }
    return !modified || wifiMgr.saveConfiguration();

}
项目:RxAndroidTBP    文件:NetworkUtil.java   
public static void removeSSIDFromConfiguredNetwork(Context context, String ssid) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

    if (!wifiManager.isWifiEnabled())
        wifiManager.setWifiEnabled(true);

    List<WifiConfiguration> configuredWifiList = wifiManager.getConfiguredNetworks();
    for (int x = 0; x < configuredWifiList.size(); x++) {
        WifiConfiguration i = configuredWifiList.get(x);
        if (i.SSID != null && i.SSID.equals("\"" + ssid + "\"")) {
            Log.w(TAG, "Removing network: " + i.SSID);
            wifiManager.removeNetwork(i.networkId);
            return;
        }
    }
}
项目:Nird2    文件:AndroidSecureRandomProvider.java   
@Override
protected void writeToEntropyPool(DataOutputStream out) throws IOException {
    super.writeToEntropyPool(out);
    out.writeInt(android.os.Process.myPid());
    out.writeInt(android.os.Process.myTid());
    out.writeInt(android.os.Process.myUid());
    if (Build.FINGERPRINT != null) out.writeUTF(Build.FINGERPRINT);
    if (Build.SERIAL != null) out.writeUTF(Build.SERIAL);
    ContentResolver contentResolver = appContext.getContentResolver();
    String id = Settings.Secure.getString(contentResolver, ANDROID_ID);
    if (id != null) out.writeUTF(id);
    Parcel parcel = Parcel.obtain();
    WifiManager wm =
            (WifiManager) appContext.getSystemService(WIFI_SERVICE);
    List<WifiConfiguration> configs = wm.getConfiguredNetworks();
    if (configs != null) {
        for (WifiConfiguration config : configs)
            parcel.writeParcelable(config, 0);
    }
    BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
    if (bt != null) {
        for (BluetoothDevice device : bt.getBondedDevices())
            parcel.writeParcelable(device, 0);
    }
    out.write(parcel.marshall());
    parcel.recycle();
}
项目:mobly-bundled-snippets    文件:WifiManagerSnippet.java   
@Rpc(
    description =
            "Clears all configured networks. This will only work if all configured "
                    + "networks were added through this MBS instance"
)
public void wifiClearConfiguredNetworks() throws WifiManagerSnippetException {
    List<WifiConfiguration> unremovedConfigs = mWifiManager.getConfiguredNetworks();
    List<WifiConfiguration> failedConfigs = new ArrayList<>();
    if (unremovedConfigs == null) {
        throw new WifiManagerSnippetException(
                "Failed to get a list of configured networks. Is wifi disabled?");
    }
    for (WifiConfiguration config : unremovedConfigs) {
        if (!mWifiManager.removeNetwork(config.networkId)) {
            failedConfigs.add(config);
        }
    }
    if (!failedConfigs.isEmpty()) {
        throw new WifiManagerSnippetException("Failed to remove networks: " + failedConfigs);
    }
}
项目:featurea    文件:WifiUtil.java   
public int connectToAP(Context context, String networkSSID, String networkPasskey) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    for (ScanResult result : wifiManager.getScanResults()) {
        if (result.SSID.equals(networkSSID)) {
            String securityMode = getScanResultSecurity(result);
            WifiConfiguration wifiConfiguration = createAPConfiguration(networkSSID, networkPasskey, securityMode);
            int res = wifiManager.addNetwork(wifiConfiguration);
            Log.d(TAG, "# addNetwork returned " + res);
            boolean b = wifiManager.enableNetwork(res, true);
            Log.d(TAG, "# enableNetwork returned " + b);
            wifiManager.setWifiEnabled(true);
            boolean changeHappen = wifiManager.saveConfiguration();
            if (res != -1 && changeHappen) {
                Log.d(TAG, "# Change happen: " + networkSSID);
            } else {
                Log.d(TAG, "# Change NOT happen");
            }
            return res;
        }
    }
    return -1;
}
项目:mobly-bundled-snippets    文件:WifiManagerSnippet.java   
/**
 * Enable Wi-Fi Soft AP (hotspot).
 *
 * @param configuration The same format as the param wifiNetworkConfig param for wifiConnect.
 * @throws Throwable
 */
@Rpc(description = "Enable Wi-Fi Soft AP (hotspot).")
public void wifiEnableSoftAp(@Nullable JSONObject configuration) throws Throwable {
    // If no configuration is provided, the existing configuration would be used.
    WifiConfiguration wifiConfiguration = null;
    if (configuration != null) {
        wifiConfiguration = JsonDeserializer.jsonToWifiConfig(configuration);
        // Have to trim off the extra quotation marks since Soft AP logic interprets
        // WifiConfiguration.SSID literally, unlike the WifiManager connection logic.
        wifiConfiguration.SSID = JsonSerializer.trimQuotationMarks(wifiConfiguration.SSID);
    }
    if (!(boolean)
            Utils.invokeByReflection(
                    mWifiManager, "setWifiApEnabled", wifiConfiguration, true)) {
        throw new WifiManagerSnippetException("Failed to initiate turning on Wi-Fi Soft AP.");
    }
    if (!Utils.waitUntil(() -> wifiIsApEnabled() == true, 60)) {
        throw new WifiManagerSnippetException(
                "Timed out after 60s waiting for Wi-Fi Soft AP state to turn on with configuration: "
                        + configuration);
    }
}
项目:letv    文件:NetworkHelper.java   
public static boolean wifiConnection(Context context, String wifiSSID, String password) {
    WifiManager wifi = (WifiManager) context.getSystemService("wifi");
    String strQuotationSSID = "\"" + wifiSSID + "\"";
    WifiInfo wifiInfo = wifi.getConnectionInfo();
    if (wifiInfo != null && (wifiSSID.equals(wifiInfo.getSSID()) || strQuotationSSID.equals(wifiInfo.getSSID()))) {
        return true;
    }
    List<ScanResult> scanResults = wifi.getScanResults();
    if (scanResults == null || scanResults.size() == 0) {
        return false;
    }
    for (int nAllIndex = scanResults.size() - 1; nAllIndex >= 0; nAllIndex--) {
        String strScanSSID = ((ScanResult) scanResults.get(nAllIndex)).SSID;
        if (wifiSSID.equals(strScanSSID) || strQuotationSSID.equals(strScanSSID)) {
            WifiConfiguration config = new WifiConfiguration();
            config.SSID = strQuotationSSID;
            config.preSharedKey = "\"" + password + "\"";
            config.status = 2;
            return wifi.enableNetwork(wifi.addNetwork(config), false);
        }
    }
    return false;
}
项目:buildAPKsApps    文件:WifiHotspotSettingHandler.java   
public boolean setWifiApEnabled(boolean enabled) {

    if (Constants.DEBUG) {
        Log.d(TAG, "setWifiApEnabled(" + enabled + ")");
    }

    if (enabled) { // disable WiFi in any case
        mWifiManager.setWifiEnabled(false);
    }

    try {

        // TODO comment from here
        /*
        Method getWifiApConfigurationMethod = mWifiManager.getClass().getMethod("getWifiApConfiguration");
        Object config = getWifiApConfigurationMethod.invoke(mWifiManager);
        */

        // configuration = null works for many devices
        Method setWifiApEnabledMethod = mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
        return (Boolean) setWifiApEnabledMethod.invoke(mWifiManager, null, enabled);
    } catch (Exception e) {
        Log.e(TAG, "", e);
        return false;
    }
}
项目:xlight_android_native    文件:BindDeviceWiFiActivity.java   
public void TestWiFi() {
    WifiInfo wifiInfo = getWifiInfo();
    wifiAdmin.openWifi();
    WifiConfiguration tempConfig = wifiAdmin.IsExsits(wifiInfo.ssid);
    if (tempConfig != null && tempConfig.networkId != -1) {
        Log.d("XLight", "remove ssid at:" + tempConfig.networkId);
        wifiAdmin.RemoveSSID(tempConfig.networkId);
    }
    int type = 1;
    if (wifiInfo.capabilities.toUpperCase().contains("WPA")) {
        type = 3;
    } else if (wifiInfo.capabilities.toUpperCase().contains("WEP")) {
        type = 2;
    }
    wifiAdmin.addNetwork(wifiAdmin.CreateWifiInfo(wifiInfo.ssid, wifiInfo.password, type));
}
项目:xlight_android_native    文件:BindDeviceSearchActivity.java   
public void connectWifi(String ssid) {
    //停止扫描
    stopScanWifi = true;
    updateWifiHandler.removeCallbacks(runnable);
    Log.d("XLight", "connect to photon wifi");
    //连接到此网络
    WifiAdmin wifiAdmin = new WifiAdmin(this);
    WifiConfiguration tempConfig = wifiAdmin.IsExsits(ssid);
    if (tempConfig != null && tempConfig.networkId != -1) {
        Log.d("XLight", "photon netId:" + tempConfig.networkId);
        mWifiManager.enableNetwork(tempConfig.networkId, true);
    } else
        wifiAdmin.addNetwork(wifiAdmin.CreateWifiInfo(ssid, "", 1));
    //连接失败回到自己的网络
    mWifiManager.reconnect();
}
项目:buildAPKsSamples    文件:WifiInfoActivity.java   
public void onClick(View v) {
    out.setText("");

    out.append("\n\nConfigured Networks:");
    // Get IP Address
    int ipAddress = wifimanager.getConnectionInfo().getIpAddress();
    out.append("\nThe ip address is "
            + Formatter.formatIpAddress(ipAddress));

    // Get configured networks
    List<WifiConfiguration> configuredNetworks = wifimanager.getConfiguredNetworks();
    for (WifiConfiguration conf : configuredNetworks) {
        out.append(String.format("\n%s", conf.SSID));
    }

    wifimanager.startScan();
}
项目:iosched-reader    文件:WiFiUtils.java   
/**
 * Helper method to decide whether to bypass conference WiFi setup.  Return true if
 * WiFi AP is already configured (WiFi adapter enabled) or WiFi configuration is complete
 * as per shared preference.
 */
public static boolean shouldBypassWiFiSetup(final Context context) {
    final WifiManager wifiManager =
            (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

    // Is WiFi on?
    if (wifiManager.isWifiEnabled()) {
        // Check for existing APs.
        final List<WifiConfiguration> configs = wifiManager.getConfiguredNetworks();
        final String conferenceSSID = getConferenceWifiConfig().SSID;
        for(WifiConfiguration config : configs) {
            if (conferenceSSID.equalsIgnoreCase(config.SSID)) return true;
        }
    }

    return WIFI_CONFIG_DONE.equals(getWiFiConfigStatus(context));
}
项目:WifiUtils    文件:ConfigSecurities.java   
@Nullable
static WifiConfiguration getWifiConfiguration(@NonNull final WifiManager wifiMgr, @NonNull final WifiConfiguration configToFind) {
    final String ssid = configToFind.SSID;
    if (ssid.isEmpty()) {
        return null;
    }

    final String bssid = configToFind.BSSID;

    final String security = getSecurity(configToFind);


    final List<WifiConfiguration> configurations = wifiMgr.getConfiguredNetworks();
    if (configurations == null) {
        wifiLog("NULL configs");
        return null;
    }

    for (final WifiConfiguration config : configurations) {
        if (bssid.equals(config.BSSID) || ssid.equals(config.SSID)) {
            final String configSecurity = getSecurity(config);
            if (Objects.equals(security, configSecurity))
                return config;
        }
    }
    wifiLog("Couldn't find " + ssid);
    return null;
}
项目:WifiUtils    文件:ConnectorUtils.java   
private static int getMaxPriority(@NonNull final WifiManager wifiManager) {
    final List<WifiConfiguration> configurations = wifiManager.getConfiguredNetworks();
    int pri = 0;
    for (final WifiConfiguration config : configurations) {
        if (config.priority > pri) {
            pri = config.priority;
        }
    }
    return pri;
}
项目:WifiUtils    文件:ConnectorUtils.java   
private static int shiftPriorityAndSave(@NonNull final WifiManager wifiMgr) {
    final List<WifiConfiguration> configurations = wifiMgr.getConfiguredNetworks();
    sortByPriority(configurations);
    final int size = configurations.size();
    for (int i = 0; i < size; i++) {
        final WifiConfiguration config = configurations.get(i);
        config.priority = i;
        wifiMgr.updateNetwork(config);
    }
    wifiMgr.saveConfiguration();
    return size;
}
项目:WifiUtils    文件:ConnectorUtils.java   
private static boolean connectToConfiguredNetwork(@NonNull WifiManager wifiManager, @Nullable WifiConfiguration config, boolean reassociate) {
    if (config == null)
        return false;

    if (Build.VERSION.SDK_INT >= 23)
        return disableAllButOne(wifiManager, config) && (reassociate ? wifiManager.reassociate() : wifiManager.reconnect());

    int oldPri = config.priority;
    // Make it the highest priority.
    int newPri = getMaxPriority(wifiManager) + 1;
    if (newPri > MAX_PRIORITY) {
        newPri = shiftPriorityAndSave(wifiManager);
        config = ConfigSecurities.getWifiConfiguration(wifiManager, config);
        if (config == null)
            return false;
    }

    // Set highest priority to this configured network
    config.priority = newPri;
    int networkId = wifiManager.updateNetwork(config);
    if (networkId == -1)
        return false;

    // Do not disable others
    if (!wifiManager.enableNetwork(networkId, false)) {
        config.priority = oldPri;
        return false;
    }

    if (!wifiManager.saveConfiguration()) {
        config.priority = oldPri;
        return false;
    }

    // We have to retrieve the WifiConfiguration after save.
    config = ConfigSecurities.getWifiConfiguration(wifiManager, config);
    return config != null && disableAllButOne(wifiManager, config) && (reassociate ? wifiManager.reassociate() : wifiManager.reconnect());

}
项目:WifiUtils    文件:ConnectorUtils.java   
private static boolean disableAllButOne(@NonNull final WifiManager wifiManager, @Nullable final WifiConfiguration config) {
    @Nullable final List<WifiConfiguration> configurations = wifiManager.getConfiguredNetworks();
    if (configurations == null || config == null || configurations.isEmpty())
        return false;
    boolean result = false;

    for (WifiConfiguration wifiConfig : configurations)
        if (wifiConfig.networkId == config.networkId)
            result = wifiManager.enableNetwork(wifiConfig.networkId, true);
        else
            wifiManager.disableNetwork(wifiConfig.networkId);
    wifiLog("disableAllButOne " + result);
    return result;
}
项目:WifiUtils    文件:ConnectorUtils.java   
@SuppressWarnings("UnusedReturnValue")
private static boolean disableAllButOne(@NonNull final WifiManager wifiManager, @Nullable final ScanResult scanResult) {
    @Nullable final List<WifiConfiguration> configurations = wifiManager.getConfiguredNetworks();
    if (configurations == null || scanResult == null || configurations.isEmpty())
        return false;
    boolean result = false;
    for (WifiConfiguration wifiConfig : configurations)
        if (Objects.equals(scanResult.BSSID, wifiConfig.BSSID) && Objects.equals(scanResult.SSID, trimQuotes(wifiConfig.SSID)))
            result = wifiManager.enableNetwork(wifiConfig.networkId, true);
        else
            wifiManager.disableNetwork(wifiConfig.networkId);
    return result;
}
项目:phonk    文件:PNetwork.java   
@ProtoMethod(description = "Connect to mContext given Wifi network with mContext given 'wpa', 'wep', 'open' type and mContext password", example = "")
@ProtoMethodParam(params = {"ssidName", "type", "password"})
public void connectWifi(String networkSSID, String type, String networkPass) {

    WifiConfiguration conf = new WifiConfiguration();
    conf.SSID = "\"" + networkSSID + "\""; // Please note the quotes. String
    // should contain ssid in quotes

    if (type.equals("wep")) {
        // wep
        conf.wepKeys[0] = "\"" + networkPass + "\"";
        conf.wepTxKeyIndex = 0;
        conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
        conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
    } else if (type.equals("wpa")) {
        // wpa
        conf.preSharedKey = "\"" + networkPass + "\"";
    } else if (type.equals("open")) {
        // open
        conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
    }

    WifiManager wifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
    wifiManager.addNetwork(conf);

    List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
    for (WifiConfiguration i : list) {
        if (i.SSID != null && i.SSID.equals("\"" + networkSSID + "\"")) {
            wifiManager.disconnect();
            wifiManager.enableNetwork(i.networkId, true);
            wifiManager.reconnect();

            break;
        }
    }

}
项目:localcloud_fe    文件:WifiWizard.java   
/**
 *    This method takes a given String, searches the current list of configured WiFi
 *     networks, and returns the networkId for the network if the SSID matches. If not,
 *     it returns -1.
 */
private int ssidToNetworkId(String ssid) {
    List<WifiConfiguration> currentNetworks = wifiManager.getConfiguredNetworks();
    int networkId = -1;

    // For each network in the list, compare the SSID with the given one
    for (WifiConfiguration test : currentNetworks) {
        if ( test.SSID.equals(ssid) ) {
            networkId = test.networkId;
        }
    }

    return networkId;
}
项目:WifiUtils    文件:ConnectorUtils.java   
static boolean cleanPreviousConfiguration(@NonNull final WifiManager wifiManager, @Nullable final WifiConfiguration config) {
    //On Android 6.0 (API level 23) and above if my app did not create the configuration in the first place, it can not remove it either.

    wifiLog("Attempting to remove previous network config...");
    if (config == null)
        return true;

    if (wifiManager.removeNetwork(config.networkId)) {
        wifiManager.saveConfiguration();
        return true;
    }
    return false;
}
项目:keepass2android    文件:WifiConfigManager.java   
private static WifiConfiguration changeNetworkCommon(WifiParsedResult wifiResult) {
  WifiConfiguration config = new WifiConfiguration();
  config.allowedAuthAlgorithms.clear();
  config.allowedGroupCiphers.clear();
  config.allowedKeyManagement.clear();
  config.allowedPairwiseCiphers.clear();
  config.allowedProtocols.clear();
  // Android API insists that an ascii SSID must be quoted to be correctly handled.
  config.SSID = quoteNonHex(wifiResult.getSsid());
  config.hiddenSSID = wifiResult.isHidden();
  return config;
}
项目:RxAndroidTBP    文件:SmartConfigClientImpl.java   
private void connectPreviousNetwork(String ssidToAdd, String password) {
    ScanResult scanResult = NetworkUtil.getWifiScanResultWithSSID(mContext, ssidToAdd);
    if (scanResult == null) {
        Timber.i("connectPreviousNetwork>> Not found scan result = %s", ssidToAdd);
        checkParams();
        return;
    }
    WifiNetworkUtils.getInstance(mContext).clearCallback();
    WifiConfiguration configuration = NetworkUtil.getWifiConfigurationWithInfo(mContext, ssidToAdd, NetworkUtil.getScanResultSecurity(scanResult), password);
    WifiNetworkUtils.getInstance(mContext).connectToWifi(configuration, mContext, new WifiNetworkUtils.BitbiteNetworkUtilsCallback() {
        @Override
        public void successfullyConnectedToNetwork(String ssid) {
            mIsSearching = true;
            Timber.i("connectPreviousNetwork>> Connected to SSID in profile added to SL device: \"" + ssidToAdd + "\"." +
                    " Searching for new SL devices in the local network for cfg verification: Activating Ping Bcast + UDPBcastServer + mDNS discovery");
            mFindDevicePresenter.startPing();
            mFindDevicePresenter.restartUdp();

            if (!mDeviceFound) {
                scanForDevices();
            }
        }

        @Override
        public void failedToConnectToNetwork(WifiNetworkUtils.WifiConnectionFailure failure) {
            Timber.e("connectPreviousNetwork>> Connect old network for confirm config device is failed = %s", failure.toString());
            propagateError(mConfigurationToyNetOutput,
                    new ConfigurationToyNetException(ConfigurationToyNetException.Reason.CANNOT_CONNECT_PREVIOS_WIFI, failure.toString()));
        }
    }, true);
}
项目:FreeStreams-TVLauncher    文件:WiFiAdmin.java   
public int AddNetwork(WifiConfiguration configuration) {
    int configurationId = mWifiManager.addNetwork(configuration);
    boolean b = mWifiManager.enableNetwork(configurationId, true);
    System.out.println("configurationId---------->" + configurationId);
    System.out.println("b---------->" + b);
    return configurationId;
}
项目:keepass2android    文件:WifiConfigManager.java   
private static Integer findNetworkInExistingConfig(WifiManager wifiManager, String ssid) {
  Iterable<WifiConfiguration> existingConfigs = wifiManager.getConfiguredNetworks();
  for (WifiConfiguration existingConfig : existingConfigs) {
    if (existingConfig.SSID.equals(ssid)) {
      return existingConfig.networkId;
    }
  }
  return null;
}
项目:WifiChatSharing    文件:MainActivity.java   
@Override
protected Void doInBackground(Void... params) {

    WifiConfiguration conf = new WifiConfiguration();
    conf.SSID = "\"" + networkSSID + "\"";
    conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);

    WifiManager wifiManager = (WifiManager) getBaseContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    wifiManager.addNetwork(conf);
    if (!wifiManager.isWifiEnabled()) {
        wifiManager.setWifiEnabled(true);
        wifiManager.startScan();
    }

    int netId = wifiManager.addNetwork(conf);
    wifiManager.disconnect();
    wifiManager.enableNetwork(netId, true);
    wifiManager.reconnect();

    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            Toast.makeText(getApplicationContext(), "Joined to " + networkSSID, Toast.LENGTH_SHORT).show();
            System.out.println("SUCCESS ");
        }
    });
    return null;
}
项目:mobile-store    文件:StartSwapView.java   
private void uiUpdateWifiNetwork() {

        viewWifiId.setText(FDroidApp.ipAddressString);
        viewWifiId.setVisibility(TextUtils.isEmpty(FDroidApp.ipAddressString) ? View.GONE : View.VISIBLE);

        WifiApControl wifiAp = WifiApControl.getInstance(getActivity());
        if (wifiAp != null && wifiAp.isWifiApEnabled()) {
            WifiConfiguration config = wifiAp.getConfiguration();
            viewWifiNetwork.setText(getContext().getString(R.string.swap_active_hotspot, config.SSID));
        } else if (TextUtils.isEmpty(FDroidApp.ssid)) {
            // not connected to or setup with any wifi network
            viewWifiNetwork.setText(R.string.swap_no_wifi_network);
        } else {
            // connected to a regular wifi network
            viewWifiNetwork.setText(FDroidApp.ssid);
        }
    }
项目:FreeStreams-TVLauncher    文件:WiFiAdmin.java   
public WiFiAdmin(Context context) {
    // 取得wifimannager
    mWifiManager = (WifiManager) context
            .getSystemService(Context.WIFI_SERVICE);
    // 取得wifiinfo
    mWifiInfo = mWifiManager.getConnectionInfo();
    mWifiList=new ArrayList<ScanResult>();
    mWifiConfigurations=new ArrayList<WifiConfiguration>();
}
项目:siiMobilityAppKit    文件:WifiWizard.java   
/**
 *    This method takes a given String, searches the current list of configured WiFi
 *     networks, and returns the networkId for the network if the SSID matches. If not,
 *     it returns -1.
 */
private int ssidToNetworkId(String ssid) {
    List<WifiConfiguration> currentNetworks = wifiManager.getConfiguredNetworks();
    int networkId = -1;

    // For each network in the list, compare the SSID with the given one
    for (WifiConfiguration test : currentNetworks) {
        if ( test.SSID.equals(ssid) ) {
            networkId = test.networkId;
        }
    }

    return networkId;
}
项目:localcloud_fe    文件:WifiWizard.java   
/**
 *    This method takes a given String, searches the current list of configured WiFi
 *     networks, and returns the networkId for the network if the SSID matches. If not,
 *     it returns -1.
 */
private int ssidToNetworkId(String ssid) {
    List<WifiConfiguration> currentNetworks = wifiManager.getConfiguredNetworks();
    int networkId = -1;

    // For each network in the list, compare the SSID with the given one
    for (WifiConfiguration test : currentNetworks) {
        if ( test.SSID.equals(ssid) ) {
            networkId = test.networkId;
        }
    }

    return networkId;
}
项目:localcloud_fe    文件:WifiWizard.java   
/**
 *    This method uses the callbackContext.success method to send a JSONArray
 *    of the currently configured networks.
 *
 *    @param    callbackContext        A Cordova callback context
 *    @param    data                JSON Array, with [0] being SSID to connect
 *    @return    true if network disconnected, false if failed
 */
private boolean listNetworks(CallbackContext callbackContext) {
    Log.d(TAG, "WifiWizard: listNetworks entered.");
    List<WifiConfiguration> wifiList = wifiManager.getConfiguredNetworks();

    JSONArray returnList = new JSONArray();

    for (WifiConfiguration wifi : wifiList) {
        returnList.put(wifi.SSID);
    }

    callbackContext.success(returnList);

    return true;
}
项目:cordova-plugins-auto-wifi    文件:WifiAdmin.java   
public void addNetwork(WifiConfiguration wcg) {
    int wcgID = wcg.networkId;
    if (wcg.networkId == -1)
        wcgID = mWifiManager.addNetwork(wcg);
    boolean b =  mWifiManager.enableNetwork(wcgID, true);
    System.out.println("a--" + wcgID);
    System.out.println("b--" + b);
}
项目:GravityBox    文件:WifiPriorityActivity.java   
private void reloadNetworks() {
    mNetworks = new ArrayList<WifiNetwork>();
    List<WifiConfiguration> networks = mWifiManager.getConfiguredNetworks();
    if (networks == null) return;

    // Sort network list by priority (or by network id if the priority is the same)
    Collections.sort(networks, new Comparator<WifiConfiguration>() {
        @Override
        public int compare(WifiConfiguration lhs, WifiConfiguration rhs) {
            // > priority -- > lower position
            if (lhs.priority < rhs.priority) return 1;
            if (lhs.priority > rhs.priority) return -1;
            // < network id -- > lower position
            if (lhs.networkId < rhs.networkId) return -1;
            if (lhs.networkId > rhs.networkId) return 1;
            return 0;
        }
    });

    // read trusted SSIDs from prefs
    Set<String> trustedNetworks = mPrefs.getStringSet(PREF_KEY_WIFI_TRUSTED,
            new HashSet<String>());
    for (WifiConfiguration c : networks) {
        WifiNetwork wn = new WifiNetwork(c);
        wn.trusted = trustedNetworks.contains(filterSSID(c.SSID));
        mNetworks.add(wn);
    }

    // remove forgotten networks from trusted list
    boolean shouldUpdatePrefs = false;
    for (String ssid : trustedNetworks) {
        if (!containsNetwork(ssid)) {
            shouldUpdatePrefs = true;
            break;
        }
    }
    if (shouldUpdatePrefs) {
        saveTrustedNetworks();
    }
}
项目:cordova-plugins-auto-wifi    文件:WifiAdmin.java   
private WifiConfiguration IsExsits(String SSID)
{
    List<WifiConfiguration> existingConfigs = mWifiManager.getConfiguredNetworks();
    for (WifiConfiguration existingConfig : existingConfigs)
    {
        if (existingConfig.SSID.equals("\""+SSID+"\""))
        {
            return existingConfig;
        }
    }
    return null;
}
项目:YiZhi    文件:WifiAutoConnectManager.java   
private WifiConfiguration isExsits(String SSID) {
    List<WifiConfiguration> existingConfigs = wifiManager
            .getConfiguredNetworks();
    for (WifiConfiguration existingConfig : existingConfigs) {
        if (existingConfig.SSID.equals("\"" + SSID + "\"")) {
            return existingConfig;
        }
    }
    return null;
}
项目:YiZhi    文件:WifiAutoConnectManager.java   
@Override
public void run() {
    // 打开wifi
    openWifi();
    // 开启wifi功能需要一段时间(我在手机上测试一般需要1-3秒左右),所以要等到wifi
    // 状态变成WIFI_STATE_ENABLED的时候才能执行下面的语句
    while (wifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLING) {
        try {
            // 为了避免程序一直while循环,让它睡个100毫秒检测……
            Thread.sleep(100);

        } catch (InterruptedException ie) {
            LogUtils.e(ie.toString());
        }
    }

    WifiConfiguration tempConfig = isExsits(ssid);

    if (tempConfig != null) {
        boolean b = wifiManager.enableNetwork(tempConfig.networkId,
                true);
    } else {
        WifiConfiguration wifiConfig = createWifiInfo(ssid, password,
                type);
        if (wifiConfig == null) {
            LogUtils.d("wifiConfig is null!");
            return;
        }

        int netID = wifiManager.addNetwork(wifiConfig);
        boolean enabled = wifiManager.enableNetwork(netID, true);
        LogUtils.d("enableNetwork status enable=" + enabled);
        boolean connected = wifiManager.reconnect();
        LogUtils.d("enableNetwork connected=" + connected);
    }

}