您好,欢迎访问代理记账网站
  • 价格透明
  • 信息保密
  • 进度掌控
  • 售后无忧

Wifi相关知识

  • 监听wifi开关及连接wifi的名称

WifiStatusTracker
private static final IntentFilter INTENT_FILTER;
static {
    INTENT_FILTER = new IntentFilter();
    INTENT_FILTER.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
    INTENT_FILTER.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
    INTENT_FILTER.addAction(WifiManager.RSSI_CHANGED_ACTION);
}


public void handleBroadcast(Intent intent) {
    String action = intent.getAction();
    if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
        updateWifiState();
    } else if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
        updateWifiState();
        final NetworkInfo networkInfo =
                intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
        connected = networkInfo != null && networkInfo.isConnected();
        mWifiInfo = null;
        ssid = null;
        if (connected) {
            mWifiInfo = mWifiManager.getConnectionInfo();
            if (mWifiInfo != null) {
                ssid = getValidSsid(mWifiInfo);
                updateRssi(mWifiInfo.getRssi());
                maybeRequestNetworkScore();
            }
        }
        updateStatusLabel();
    } else if (action.equals(WifiManager.RSSI_CHANGED_ACTION)) {
        // Default to -200 as its below WifiManager.MIN_RSSI.
        updateRssi(intent.getIntExtra(WifiManager.EXTRA_NEW_RSSI, -200));
        updateStatusLabel();
    }
}

 

 

  • 通过WifiInfo找configuration

mLastInfo = mWifiManager.getConnectionInfo();
if (mLastInfo != null) {
    connectionConfig = getWifiConfigurationForNetworkId(mLastInfo.getNetworkId(),
            mWifiManager.getConfiguredNetworks());
}
private WifiConfiguration getWifiConfigurationForNetworkId(
        int networkId, final List<WifiConfiguration> configs) {
    if (configs != null) {
        for (WifiConfiguration config : configs) {
            if (mLastInfo != null && networkId == config.networkId &&
                    !(config.selfAdded && config.numAssociation == 0)) {
                return config;
            }
        }
    }
    return null;
}

 

  • 获取 ScanResult 加密方式
public static final int SECURITY_NONE = 0;
public static final int SECURITY_WEP = 1;
public static final int SECURITY_PSK = 2;
public static final int SECURITY_EAP = 3;
public static final int SECURITY_OWE = 4;
public static final int SECURITY_SAE = 5;
public static final int SECURITY_DPP = 6;

private static int getSecurity(ScanResult result) {
    if (result.capabilities.contains("DPP")) {
        return SECURITY_DPP;
    } else if (result.capabilities.contains("SAE")) {
        return SECURITY_SAE;
    } else if (result.capabilities.contains("OWE")) {
        return SECURITY_OWE;
    } else if (result.capabilities.contains("WEP")) {
        return SECURITY_WEP;
    } else if (result.capabilities.contains("PSK")) {
        return SECURITY_PSK;
    } else if (result.capabilities.contains("EAP")) {
        return SECURITY_EAP;
    }
    return SECURITY_NONE;
}

  • 获取wifiConfiguragion 加密方式

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;
    }
    if (config.allowedKeyManagement.get(KeyMgmt.DPP)) {
        return SECURITY_DPP;
    }
    if (config.allowedKeyManagement.get(KeyMgmt.SAE)) {
        return SECURITY_SAE;
    }
    if (config.allowedKeyManagement.get(KeyMgmt.OWE)) {
        return SECURITY_OWE;
    }
    return (config.wepKeys[0] != null) ? SECURITY_WEP : SECURITY_NONE;
}

 

  • 获取wifi异常信息
if (config != null && !config.getNetworkSelectionStatus().isNetworkEnabled()) {
    WifiConfiguration.NetworkSelectionStatus networkStatus =
            config.getNetworkSelectionStatus();
    switch (networkStatus.getNetworkSelectionDisableReason()) {
        case WifiConfiguration.NetworkSelectionStatus.DISABLED_AUTHENTICATION_FAILURE:
            summary.append(mContext.getString(R.string.wifi_disabled_password_failure));
            break;
        case WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD:
            summary.append(mContext.getString(R.string.wifi_check_password_try_again));
            break;
        case WifiConfiguration.NetworkSelectionStatus.DISABLED_DHCP_FAILURE:
        case WifiConfiguration.NetworkSelectionStatus.DISABLED_DNS_FAILURE:
            summary.append(mContext.getString(R.string.wifi_disabled_network_failure));
            break;
        case WifiConfiguration.NetworkSelectionStatus.DISABLED_ASSOCIATION_REJECTION:
            summary.append(mContext.getString(R.string.wifi_disabled_generic));
            break;
    }
} 

 

 

 

 

 

 


分享:

低价透明

统一报价,无隐形消费

金牌服务

一对一专属顾问7*24小时金牌服务

信息保密

个人信息安全有保障

售后无忧

服务出问题客服经理全程跟进