How to get the connection strength of Wifi access points?

前端 未结 5 1958
谎友^
谎友^ 2020-12-05 01:09

I am building an application reading the signal strength of each available Wifi access point.

I\'ve written code like:

    wifi = (WifiManager) getS         


        
5条回答
  •  情话喂你
    2020-12-05 01:41

    private void checkNetworkStrengh() {
            ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo Info = cm.getActiveNetworkInfo();
            if (Info == null || !Info.isConnectedOrConnecting()) {
                Log.i(TAG, "No connection");
            } else {
                int netType = Info.getType();
                int netSubtype = Info.getSubtype();
    
                if (netType == ConnectivityManager.TYPE_WIFI) {
                    Log.i(TAG, "Wifi connection");
                    WifiManager wifiManager = (WifiManager) getApplication().getSystemService(Context.WIFI_SERVICE);
                    List scanResult = wifiManager.getScanResults();
                    for (int i = 0; i < scanResult.size(); i++) {
                        Log.d("scanResult", "Speed of wifi"+scanResult.get(i).level);//The db level of signal 
                    }
    
    
                    // Need to get wifi strength
                } else if (netType == ConnectivityManager.TYPE_MOBILE) {
                    Log.i(TAG, "GPRS/3G connection");
                    // Need to get differentiate between 3G/GPRS
                }
            }
        }
    

提交回复
热议问题