本文整理汇总了Java中android.net.wifi.WifiConfiguration.KeyMgmt类的典型用法代码示例。如果您正苦于以下问题:Java KeyMgmt类的具体用法?Java KeyMgmt怎么用?Java KeyMgmt使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
KeyMgmt类属于android.net.wifi.WifiConfiguration包,在下文中一共展示了KeyMgmt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getWiFiPassword
import android.net.wifi.WifiConfiguration.KeyMgmt; //导入依赖的package包/类
private String getWiFiPassword(Context context, int networkId) {
final WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
@SuppressWarnings("unchecked")
final List<WifiConfiguration> list = (List<WifiConfiguration>) XposedHelpers.callMethod(wifiManager, "getPrivilegedConfiguredNetworks");
String pwd;
for (WifiConfiguration config : list) {
if (config.networkId == networkId) {
if (config.allowedKeyManagement.get(KeyMgmt.WPA_PSK)) {
pwd = config.preSharedKey;
} else {
pwd = config.wepKeys[config.wepTxKeyIndex];
}
if (pwd != null) {
return pwd.replaceAll("^\"|\"$", "");
}
}
}
return null;
}
示例2: setWifiApEnabled
import android.net.wifi.WifiConfiguration.KeyMgmt; //导入依赖的package包/类
public boolean setWifiApEnabled(boolean enabled) {
boolean ok = false;
if (enabled) {
savedApConfig_ = getWifiApConfiguration();
ok = setWifiApEnabled(wifiConfig, enabled);
}
else {
// return to previous settings
if (savedApConfig_.SSID.isEmpty() || savedApConfig_.SSID.equals(wifiConfig.SSID)) {
// in case of no previous settings or error where
// previous settings are the same as current settings AndroidAP with no
// password
savedApConfig_.SSID = "AndroidAP";
savedApConfig_.allowedKeyManagement.set(KeyMgmt.NONE);
}
restoreSavedAp_ = true;
// disabling
ok = setWifiApEnabled(wifiConfig, enabled);
}
return ok;
}
示例3: connectToSocketWifi
import android.net.wifi.WifiConfiguration.KeyMgmt; //导入依赖的package包/类
/**
* 连接指定
*
* @param manager
* @param wifiSSID
* @return
*/
public static boolean connectToSocketWifi(WifiManager manager, String wifiSSID) {
LogUtils.i("要连接的socket wifi====>" + wifiSSID);
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.SSID = "\"" + wifiSSID + "\"";
wifiConfiguration.allowedKeyManagement.set(KeyMgmt.NONE);
wifiConfiguration.wepKeys[0] = "\"" + "\""; //小米手机MIUI7/华为EMUI4.1 需要webKey
int networkId = manager.addNetwork(wifiConfiguration);
if (networkId != -1) {
manager.enableNetwork(networkId, true);
e("连接设备成功");
return true;
} else {
e("第一次连接失败,尝试第二次。");
WifiConfiguration wifiConfiguration2 = new WifiConfiguration();
wifiConfiguration2.SSID = "\"" + wifiSSID + "\"";
//wifiConfiguration.wepKeys[0] = "\"" + "\"";//去掉webKey //小米手机MIUI8不能有webKey
wifiConfiguration2.allowedKeyManagement.set(KeyMgmt.NONE);
networkId = manager.addNetwork(wifiConfiguration2);
if (networkId != -1) {
manager.enableNetwork(networkId, true);
e("连接设备成功");
return true;
}
e("连接设备失败");
}
return false;
}
示例4: getWifiConfiguration
import android.net.wifi.WifiConfiguration.KeyMgmt; //导入依赖的package包/类
/**
* 获取要连接的wifi节点各个配置选项的加密类型
*
* @param ssid
* @return wifiConfiguration
*/
public static WifiConfiguration getWifiConfiguration(WifiManager manager, String ssid, String
password) {
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.SSID = "\"" + ssid + "\"";
List<ScanResult> list = manager.getScanResults();
for (ScanResult scResult : list) {
if (ssid.equals(scResult.SSID)) {
String capabilities = scResult.capabilities;
LogUtils.i("capabilities=" + capabilities);
if (capabilities.contains("WEP") || capabilities.contains("wep")) {
wifiConfiguration.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
wifiConfiguration.preSharedKey = "\"" + password + "\"";
LogUtils.i("wep");
} else if (capabilities.contains("WPA") || capabilities.contains("wpa")) {
wifiConfiguration.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
wifiConfiguration.preSharedKey = "\"" + password + "\"";
LogUtils.i("wpa");
} else {
wifiConfiguration.allowedKeyManagement.set(KeyMgmt.NONE);
LogUtils.i("none");
}
}
}
return wifiConfiguration;
}
示例5: getSecurity
import android.net.wifi.WifiConfiguration.KeyMgmt; //导入依赖的package包/类
public static int getSecurity(WifiConfiguration config) {
if (config.wepKeys[0] != null) {
return SECURITY_WEP;
}
if (config.allowedKeyManagement.get(KeyMgmt.WPA_PSK)) {
return SECURITY_PSK;
}
if (config.allowedKeyManagement.get(KeyMgmt.WPA_EAP) || config.allowedKeyManagement.get(KeyMgmt.IEEE8021X)) {
return SECURITY_EAP_OR_IEEE8021X;
}
return SECURITY_NONE;
}
示例6: getSecurity
import android.net.wifi.WifiConfiguration.KeyMgmt; //导入依赖的package包/类
static int getSecurity(WifiConfiguration config) {
if (config.allowedKeyManagement.get(KeyMgmt.WPA_PSK)) {
return SECURITY_PSK;
}
if (config.allowedKeyManagement.get(KeyMgmt.WPA_EAP) ||
config.allowedKeyManagement.get(KeyMgmt.IEEE8021X)) {
return SECURITY_EAP;
}
return (config.wepKeys[0] != null) ? SECURITY_WEP : SECURITY_NONE;
}
示例7: generateOpenNetworkConfig
import android.net.wifi.WifiConfiguration.KeyMgmt; //导入依赖的package包/类
/**
* Generate and save a default wifiConfiguration with common values. Can
* only be called for unsecured networks.
*
* @hide
*/
protected void generateOpenNetworkConfig() {
if (security != SECURITY_NONE)
throw new IllegalStateException();
if (mConfig != null)
return;
mConfig = new WifiConfiguration();
mConfig.SSID = AccessPoint.convertToQuotedString(ssid);
mConfig.allowedKeyManagement.set(KeyMgmt.NONE);
}
示例8: isInsecure
import android.net.wifi.WifiConfiguration.KeyMgmt; //导入依赖的package包/类
private static boolean isInsecure(final WifiConfiguration wc) {
for (final String s : wc.wepKeys) {
if (s != null) {
return false;
}
}
return wc.allowedKeyManagement.get(KeyMgmt.NONE);
}
示例9: getSecurity
import android.net.wifi.WifiConfiguration.KeyMgmt; //导入依赖的package包/类
/**
* Gets the security type of a WifiConfiguration
* @param config WifiConfiguration whose security is to be found out
* @return security of the given WifiConfiguration
*/
public static String getSecurity(WifiConfiguration config) {
if (config.allowedKeyManagement.get(KeyMgmt.WPA_PSK)) {
return SECURITY_PSK;
}
if (config.allowedKeyManagement.get(KeyMgmt.WPA_EAP) ||
config.allowedKeyManagement.get(KeyMgmt.IEEE8021X)) {
return SECURITY_EAP;
}
return (config.wepKeys[0] != null) ? SECURITY_WEP : SECURITY_NONE;
}
示例10: getWifiConfigurationSecurity
import android.net.wifi.WifiConfiguration.KeyMgmt; //导入依赖的package包/类
/**
* @return The security of a given {@link WifiConfiguration}.
*/
static public String getWifiConfigurationSecurity(WifiConfiguration wifiConfig) {
if (wifiConfig.allowedKeyManagement.get(KeyMgmt.NONE)) {
// If we never set group ciphers, wpa_supplicant puts all of them.
// For open, we don't set group ciphers.
// For WEP, we specifically only set WEP40 and WEP104, so CCMP
// and TKIP should not be there.
if (!wifiConfig.allowedGroupCiphers.get(GroupCipher.CCMP)
&& (wifiConfig.allowedGroupCiphers.get(GroupCipher.WEP40)
|| wifiConfig.allowedGroupCiphers.get(GroupCipher.WEP104))) {
return WEP;
} else {
return OPEN;
}
} else if (wifiConfig.allowedProtocols.get(Protocol.RSN)) {
return WPA2;
} else if (wifiConfig.allowedKeyManagement.get(KeyMgmt.WPA_EAP)) {
return WPA_EAP;
} else if (wifiConfig.allowedKeyManagement.get(KeyMgmt.IEEE8021X)) {
return IEEE8021X;
} else if (wifiConfig.allowedProtocols.get(Protocol.WPA)) {
return WPA;
} else {
Log.w(TAG, "Unknown security type from WifiConfiguration, falling back on open.");
return OPEN;
}
}
示例11: onReceive
import android.net.wifi.WifiConfiguration.KeyMgmt; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
WifiManager wfm = (WifiManager) who
.getSystemService(Context.WIFI_SERVICE);
if (wfm == null)
return;
List<ScanResult> results = wfm.getScanResults();
if (results == null)
return;
if (onWifiScanResultListener != null)
onWifiScanResultListener.run();
for (ScanResult result : results) {
if (wifiAPName.equals(result.SSID)) {
WifiConfiguration wfc = new WifiConfiguration();
wfc.SSID = "\"" + result.SSID + "\"";
wfc.allowedKeyManagement.set(KeyMgmt.NONE);
wfc.status = WifiConfiguration.Status.ENABLED;
int netId = wfm.addNetwork(wfc);
wfm.saveConfiguration();
wfm.enableNetwork(netId, true);
wfm.reconnect();
safeConnectivityReceiverRegister();
break;
}
}
}
示例12: createAccessPoint
import android.net.wifi.WifiConfiguration.KeyMgmt; //导入依赖的package包/类
private void createAccessPoint() {
wifiManager.setWifiEnabled(false);
wifiConfig = new WifiConfiguration();
wifiConfig.SSID = AP_NAME;
wifiConfig.allowedKeyManagement.set(KeyMgmt.NONE);
Method method;
try {
method = wifiManager.getClass().getMethod("setWifiApEnabled",
WifiConfiguration.class, boolean.class);
method.invoke(wifiManager, wifiConfig, true);
} catch (Exception e) {
Log.e(TAG, "", e);
}
}
示例13: closeAccessPoint
import android.net.wifi.WifiConfiguration.KeyMgmt; //导入依赖的package包/类
private void closeAccessPoint() {
wifiManager.setWifiEnabled(false);
wifiConfig = new WifiConfiguration();
wifiConfig.SSID = AP_NAME;
wifiConfig.allowedKeyManagement.set(KeyMgmt.NONE);
Method method;
try {
method = wifiManager.getClass().getMethod("setWifiApEnabled",
WifiConfiguration.class, boolean.class);
method.invoke(wifiManager, wifiConfig, false);
} catch (Exception e) {
Log.e(TAG, "", e);
}
}
示例14: configureNetwork
import android.net.wifi.WifiConfiguration.KeyMgmt; //导入依赖的package包/类
private void configureNetwork(ScanResult scanResult) {
WifiConfiguration wc = new WifiConfiguration();
wc.SSID = "\"" + scanResult.SSID + "\"";
wc.BSSID = scanResult.BSSID;
wc.status = WifiConfiguration.Status.DISABLED;
wc.priority = 40;
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wc.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
wc.status = WifiConfiguration.Status.ENABLED;
wifiManager.addNetwork(wc);
wifiManager.saveConfiguration();
}
示例15: getWifiConfigurationSecurity
import android.net.wifi.WifiConfiguration.KeyMgmt; //导入依赖的package包/类
/**
* @return The security of a given {@link WifiConfiguration}.
*/
static public String getWifiConfigurationSecurity(WifiConfiguration wifiConfig) {
if (wifiConfig.allowedKeyManagement.get(KeyMgmt.NONE)) {
// If we never set group ciphers, wpa_supplicant puts all of them.
// For open, we don't set group ciphers.
// For WEP, we specifically only set WEP40 and WEP104, so CCMP
// and TKIP should not be there.
if (!wifiConfig.allowedGroupCiphers.get(GroupCipher.CCMP)
&& (wifiConfig.allowedGroupCiphers.get(GroupCipher.WEP40) || wifiConfig.allowedGroupCiphers.get(GroupCipher.WEP104))) {
return WEP;
}
else {
return OPEN;
}
}
else if (wifiConfig.allowedProtocols.get(Protocol.RSN)) {
return WPA2;
}
else if (wifiConfig.allowedKeyManagement.get(KeyMgmt.WPA_EAP)) {
return WPA_EAP;
}
else if (wifiConfig.allowedKeyManagement.get(KeyMgmt.IEEE8021X)) {
return IEEE8021X;
}
else if (wifiConfig.allowedProtocols.get(Protocol.WPA)) {
return WPA;
}
else {
Log.w(TAG, "Unknown security type from WifiConfiguration, falling back on open.");
return OPEN;
}
}