本文整理匯總了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);
}
}
示例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();
}
示例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);
}
}
示例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;
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
}
示例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!");
}
}
}
示例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();
}
}