首页
登录 | 注册

android 实时获取wifi信号强度

 public boolean isWifiConnect() {
        ConnectivityManager connManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo mWifiInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        return mWifiInfo.isConnected();
    }

    public void checkWifiState() {
        if (isWifiConnect()) {
            WifiManager mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
            WifiInfo mWifiInfo = mWifiManager.getConnectionInfo();
            int wifi = mWifiInfo.getRssi();//获取wifi信号强度
            if (wifi > -50 && wifi < 0) {//最强
                Log.e(TAG, "最强");
            } else if (wifi > -70 && wifi < -50) {//较强
                Log.e(TAG, "较强");
            } else if (wifi > -80 && wifi < -70) {//较弱
                Log.e(TAG, "较弱");
            } else if (wifi > -100 && wifi < -80) {//微弱
                Log.e(TAG, "微弱");
            }
        } else {
            //无连接
            Log.e(TAG, "无wifi连接");
        }
    }

 



2020 jeepxie.net webmaster#jeepxie.net
10 q. 0.007 s.
京ICP备10005923号