【问题标题】:How to get encryption type of the current wifi connection without scanning all wifi networks?如何在不扫描所有 wifi 网络的情况下获取当前 wifi 连接的加密类型?
【发布时间】:2016-10-14 21:54:23
【问题描述】:

有没有办法在 Android 6.0+ 上以编程方式获取 wifi 加密类型(如 WSA、WSA2、WEP)而不使用:

WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
List<ScanResult> networkList = wifi.getScanResults();

因为我不想让用户访问位置。

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

这似乎是扫描 wifi 网络时的要求。

我希望有一种方法可以实现这一点,而无需像 android.net.wifi.WifiInfo 类那样扫描所有 wifi 网络。

【问题讨论】:

    标签: java android android-wifi android-permissions android-networking


    【解决方案1】:

    不,这是不可能的。获得当前运行 wifi 的加密类型的唯一方法是使用 android.net.wifi.WifiInfoScanResults 使用 iterations

    您可以使用以下示例获取当前运行的 Wifi 的加密类型,ScanResult

    WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    List<ScanResult> networkList = wifi.getScanResults();
    
    //get current connected SSID for comparison to ScanResult
    WifiInfo wi = wifi.getConnectionInfo();
    String currentSSID = wi.getSSID();
    
        if (networkList != null) {
            for (ScanResult network : networkList)
            {
               //check if current connected SSID
               if (currentSSID.equals(network.SSID)){
                //get capabilities of current connection
                String Capabilities =  network.capabilities;        
                Log.d (TAG, network.SSID + " capabilities : " + Capabilities);
    
                if (Capabilities.contains("WPA2")) {
                   //do something
                }
                else if (Capabilities.contains("WPA")) {
                   //do something
                }
                else if (Capabilities.contains("WEP")) {
                   //do something
                }
               }
            }
        }
    

    您可以从这里获得参考:https://stackoverflow.com/a/28906046/4360419

    【讨论】:

    • 谢谢。也许它会被添加到 AOSP 的未来版本中。
    • 如果您喜欢我的回答,请将其标记为有帮助...!
    • 还不打算接受答案,也许有人知道这样做的无证方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-27
    • 2011-02-28
    • 1970-01-01
    • 2018-12-19
    • 1970-01-01
    相关资源
    最近更新 更多