当前位置: 首页>>代码示例>>Java>>正文


Java WifiManager.saveConfiguration方法代码示例

本文整理汇总了Java中android.net.wifi.WifiManager.saveConfiguration方法的典型用法代码示例。如果您正苦于以下问题:Java WifiManager.saveConfiguration方法的具体用法?Java WifiManager.saveConfiguration怎么用?Java WifiManager.saveConfiguration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.net.wifi.WifiManager的用法示例。


在下文中一共展示了WifiManager.saveConfiguration方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateNetwork

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
/**
 * 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);
  }
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:25,代码来源:WifiConfigManager.java

示例2: checkForExcessOpenNetworkAndSave

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
@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();

}
 
开发者ID:ThanosFisherman,项目名称:WifiUtils,代码行数:25,代码来源:ConnectorUtils.java

示例3: updateNetwork

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:xiong-it,项目名称:ZXingAndroidExt,代码行数:26,代码来源:WifiConfigManager.java

示例4: shiftPriorityAndSave

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
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;
}
 
开发者ID:ThanosFisherman,项目名称:WifiUtils,代码行数:13,代码来源:ConnectorUtils.java

示例5: connectToConfiguredNetwork

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
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());

}
 
开发者ID:ThanosFisherman,项目名称:WifiUtils,代码行数:40,代码来源:ConnectorUtils.java

示例6: cleanPreviousConfiguration

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
static boolean cleanPreviousConfiguration(@NonNull final WifiManager wifiManager, @NonNull final ScanResult scanResult) {
    //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.
    final WifiConfiguration config = ConfigSecurities.getWifiConfiguration(wifiManager, scanResult);
    wifiLog("Attempting to remove previous network config...");
    if (config == null)
        return true;

    if (wifiManager.removeNetwork(config.networkId)) {
        wifiManager.saveConfiguration();
        return true;
    }
    return false;
}
 
开发者ID:ThanosFisherman,项目名称:WifiUtils,代码行数:14,代码来源:ConnectorUtils.java

示例7: connectToAP

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
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;
}
 
开发者ID:dmitrykolesnikovich,项目名称:featurea,代码行数:23,代码来源:WifiUtil.java

示例8: updateWifiConfig

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
private static void updateWifiConfig(ArrayList<WifiConfiguration> configList, ResultReceiver receiver) {
    try {
        WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
        for (WifiConfiguration c : configList) {
            wm.updateNetwork(c);
        }
        wm.saveConfiguration();
        if (receiver != null) {
            receiver.send(0, null);
        }
    } catch (Throwable t) {
        XposedBridge.log(t);
    }
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:15,代码来源:ModHwKeys.java

示例9: connectWifi

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
private void connectWifi() {
  info("Connecting to WiFi");

  final WifiManager manager = (WifiManager) getApplicationContext()
      .getSystemService(Context.WIFI_SERVICE);

  if (!manager.isWifiEnabled()) {
    info("Enabling WiFi");
    manager.setWifiEnabled(true);
  }

  if (!manager.startScan()) {
    info("Could not start a WiFi scan ...");
  }

  final List<android.net.wifi.ScanResult> list = manager.getScanResults();
  for (final android.net.wifi.ScanResult result : list) {
    if (result.SSID != null
        && result.SSID.startsWith("LGR105")
        && result.SSID.endsWith(".OSC")
        ) {
      info("Found WiFi candidate: " + result.capabilities);

      SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);

      String networkSSID = result.SSID;
      String networkPass = prefs.getString("wifipass", "");

      WifiConfiguration conf = new WifiConfiguration();
      conf.SSID = "\"" + networkSSID + "\"";
      conf.preSharedKey = "\"" + networkPass + "\"";
      conf.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);

      final int networkId = manager.addNetwork(conf);
      if (networkId != -1) {
        manager.disconnect();
        manager.enableNetwork(networkId, true);
        manager.saveConfiguration();
      }

      info("WiFi: Connected!");
    }
  }
}
 
开发者ID:mariobodemann,项目名称:osc,代码行数:45,代码来源:MainActivity.java

示例10: installConferenceWiFi

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public static void installConferenceWiFi(final Context context) {
    // Create conferenceWifiConfig
    WifiConfiguration conferenceWifiConfig = getConferenceWifiConfig();

    // Store conferenceWifiConfig.
    final WifiManager wifiManager =
            (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    int netId = wifiManager.addNetwork(conferenceWifiConfig);
    if (netId != -1) {
        wifiManager.enableNetwork(netId, false);
        boolean result = wifiManager.saveConfiguration();
        if (!result) {
            Log.e(TAG, "Unknown error while calling WiFiManager.saveConfiguration()");
            Toast.makeText(context,
                    context.getResources().getString(R.string.wifi_install_error_message),
                    Toast.LENGTH_SHORT).show();
        }
    } else {
        Log.e(TAG, "Unknown error while calling WiFiManager.addNetwork()");
        Toast.makeText(context,
                context.getResources().getString(R.string.wifi_install_error_message),
                Toast.LENGTH_SHORT).show();
    }
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:25,代码来源:WiFiUtils.java


注:本文中的android.net.wifi.WifiManager.saveConfiguration方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。