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


Java WifiConfiguration类代码示例

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


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

示例1: wifiConnection

import android.net.wifi.WifiConfiguration; //导入依赖的package包/类
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;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:24,代码来源:NetworkHelper.java

示例2: updateNetwork

import android.net.wifi.WifiConfiguration; //导入依赖的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

示例3: getWifiConfiguration

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

示例4: checkForExcessOpenNetworkAndSave

import android.net.wifi.WifiConfiguration; //导入依赖的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

示例5: drop

import android.net.wifi.WifiConfiguration; //导入依赖的package包/类
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);
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:25,代码来源:WifiPriorityActivity.java

示例6: disableAllButOne

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

示例7: ssidToNetworkId

import android.net.wifi.WifiConfiguration; //导入依赖的package包/类
/**
 *    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;
}
 
开发者ID:SUTFutureCoder,项目名称:localcloud_fe,代码行数:19,代码来源:WifiWizard.java

示例8: removeSSIDFromConfiguredNetwork

import android.net.wifi.WifiConfiguration; //导入依赖的package包/类
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;
        }
    }
}
 
开发者ID:hoanglm4,项目名称:RxAndroidTBP,代码行数:17,代码来源:NetworkUtil.java

示例9: writeToEntropyPool

import android.net.wifi.WifiConfiguration; //导入依赖的package包/类
@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();
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:28,代码来源:AndroidSecureRandomProvider.java

示例10: wifiClearConfiguredNetworks

import android.net.wifi.WifiConfiguration; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:google,项目名称:mobly-bundled-snippets,代码行数:22,代码来源:WifiManagerSnippet.java

示例11: AP

import android.net.wifi.WifiConfiguration; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:google,项目名称:mobly-bundled-snippets,代码行数:28,代码来源:WifiManagerSnippet.java

示例12: setWifiApEnabled

import android.net.wifi.WifiConfiguration; //导入依赖的package包/类
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;
	}
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:27,代码来源:WifiHotspotSettingHandler.java

示例13: TestWiFi

import android.net.wifi.WifiConfiguration; //导入依赖的package包/类
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));
}
 
开发者ID:Datatellit,项目名称:xlight_android_native,代码行数:17,代码来源:BindDeviceWiFiActivity.java

示例14: connectWifi

import android.net.wifi.WifiConfiguration; //导入依赖的package包/类
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();
}
 
开发者ID:Datatellit,项目名称:xlight_android_native,代码行数:17,代码来源:BindDeviceSearchActivity.java

示例15: onClick

import android.net.wifi.WifiConfiguration; //导入依赖的package包/类
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();
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:18,代码来源:WifiInfoActivity.java


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