android.net.wifi.WifiManager.calculateSignalLevel()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(434)

本文整理了Java中android.net.wifi.WifiManager.calculateSignalLevel()方法的一些代码示例,展示了WifiManager.calculateSignalLevel()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WifiManager.calculateSignalLevel()方法的具体详情如下:
包路径:android.net.wifi.WifiManager
类名称:WifiManager
方法名:calculateSignalLevel

WifiManager.calculateSignalLevel介绍

暂无

代码示例

代码示例来源:origin: cSploit/android

public Keygen getKeygen(ScanResult result){
 final Keygen keygen = getKeygen(result.SSID,
  result.BSSID.toUpperCase(),
  WifiManager.calculateSignalLevel(result.level, 4),
  result.capabilities);
 if(keygen != null)
  keygen.setScanResult(result);
 return keygen;
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldCalculateSignalLevelSetBefore() {
 ShadowWifiManager.setSignalLevelInPercent(0.5f);
 assertThat(WifiManager.calculateSignalLevel(0, 5)).isEqualTo(2);
 assertThat(WifiManager.calculateSignalLevel(2, 5)).isEqualTo(2);
 ShadowWifiManager.setSignalLevelInPercent(0.9f);
 assertThat(WifiManager.calculateSignalLevel(0, 5)).isEqualTo(3);
 assertThat(WifiManager.calculateSignalLevel(2, 5)).isEqualTo(3);
 ShadowWifiManager.setSignalLevelInPercent(1f);
 assertThat(WifiManager.calculateSignalLevel(0, 4)).isEqualTo(3);
 assertThat(WifiManager.calculateSignalLevel(2, 4)).isEqualTo(3);
 ShadowWifiManager.setSignalLevelInPercent(0);
 assertThat(WifiManager.calculateSignalLevel(0, 5)).isEqualTo(0);
 assertThat(WifiManager.calculateSignalLevel(2, 5)).isEqualTo(0);
}

代码示例来源:origin: NimbleDroid/FriendlyDemo

private boolean isOnGoodWIFIConnection(@NonNull NetworkInfo netInfo) {
  return (netInfo.getType() == TYPE_WIFI)
      && (WifiManager.calculateSignalLevel(wifiManager.getConnectionInfo().getRssi(), 4) > 0);
}

代码示例来源:origin: Fewlaps/flone-android

@Override
public int getStrength() {
   try {
     int rssi = wifiManager.getConnectionInfo().getRssi();
     int level = WifiManager.calculateSignalLevel(rssi, 10);
     int percentage = (int) ((level / 10.0) * 100);
     Log.d("aaa", "WiFI RSSI=" + String.valueOf(percentage));
     return percentage;
   } catch (Exception e) {
     return 0;
   }
  }
@Override

代码示例来源:origin: fennifith/Status

@Override
  public void onReceive(WifiIconData icon, Intent intent) {
    NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
    if (networkInfo == null) networkInfo = icon.connectivityManager.getActiveNetworkInfo();
    if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI && networkInfo.isConnected())
      icon.onIconUpdate(WifiManager.calculateSignalLevel(icon.wifiManager.getConnectionInfo().getRssi(), 5));
    else icon.onIconUpdate(-1);
  }
}

代码示例来源:origin: Dawish/BriskTVLauncher

@Override
  public void onReceive(Context context, Intent intent) {
    WifiManager wifiManager = (WifiManager) context
        .getSystemService(context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    if (wifiInfo.getBSSID() != null) {
      // wifi信号强度
      int signalLevel = WifiManager.calculateSignalLevel(
          wifiInfo.getRssi(), 4);
      if (signalLevel == 0) {
        imgNetWorkState.setImageDrawable(context.getResources()
            .getDrawable(R.mipmap.wifi_1));
      } else if (signalLevel == 1) {
        imgNetWorkState.setImageDrawable(context.getResources()
            .getDrawable(R.mipmap.wifi_2));
      } else if (signalLevel == 2) {
        imgNetWorkState.setImageDrawable(context.getResources()
            .getDrawable(R.mipmap.wifi_3));
      } else if (signalLevel == 3) {
        imgNetWorkState.setImageDrawable(context.getResources()
            .getDrawable(R.mipmap.networkstate_on));
      }
      if (d)
        Toast.makeText(context, "wifi level" + signalLevel,
            Toast.LENGTH_SHORT).show();
    }
  }
};

代码示例来源:origin: MoMoWait/LeanbackLauncher

public static int getWifiStrength(){
  int strength = 0;
  WifiManager wifiManager = (WifiManager) CommonValues.application.getSystemService(Context.WIFI_SERVICE); // 取得WifiManager对象
  WifiInfo info = wifiManager.getConnectionInfo();
  if (info != null) {
    strength = WifiManager.calculateSignalLevel(info.getRssi(), 5);
  }
  return strength;
}

代码示例来源:origin: n76/DejaVu

/**
 * Call back method entered when Android has completed a scan for WiFi emitters in
 * the area.
 */
private synchronized void onWiFisChanged() {
  if ((wm != null) && (emitterCache != null)) {
    List<ScanResult> scanResults = wm.getScanResults();
    Set<Observation> observations = new HashSet<>();
    for (ScanResult sr : scanResults) {
      String bssid = sr.BSSID.toLowerCase(Locale.US).replace(".", ":");
      RfEmitter.EmitterType rftype = RfEmitter.EmitterType.WLAN_24GHZ;
      if (is5GHz(sr.frequency))
        rftype = RfEmitter.EmitterType.WLAN_5GHZ;
      if (bssid != null) {
        Observation o = new Observation(bssid, rftype);
        o.setAsu(WifiManager.calculateSignalLevel(sr.level, MAXIMUM_ASU));
        o.setNote(sr.SSID);
        observations.add(o);
      }
    }
    if (!observations.isEmpty()) {
      // Log.d(TAG, "onWiFisChanged(): Observations: " + observations.toString());
      queueForProcessing(observations, System.currentTimeMillis());
    }
  }
  wifiScanInprogress = false;
}

代码示例来源:origin: fennifith/Status

@Override
public void register() {
  super.register();
  int level = WifiManager.calculateSignalLevel(wifiManager.getConnectionInfo().getRssi(), 5);
  if (level > 0)
    onIconUpdate(level); //temporary fix, cannot determine if wifi is enabled without BroadcastReceiver for some reason
}

代码示例来源:origin: n76/wifi_backend

double wgt = (WifiManager.calculateSignalLevel(dBm, 100)+1)/100.0;

代码示例来源:origin: ApolloAuto/apollo-DuerOS

if (mWifiManager.getConnectionInfo() != null) {
  int rssi = mWifiManager.getConnectionInfo().getRssi();
  int level = WifiManager.calculateSignalLevel(rssi, 4);
  switch (level) {
    case 0:

代码示例来源:origin: ApolloAuto/apollo-DuerOS

if (mWifiManager.getConnectionInfo() != null) {
  int rssi = mWifiManager.getConnectionInfo().getRssi();
  int level = WifiManager.calculateSignalLevel(rssi, 4);
  switch (level) {
    case 0:

代码示例来源:origin: ApolloAuto/apollo-DuerOS

if (mWifiManager.getConnectionInfo() != null) {
  int rssi = mWifiManager.getConnectionInfo().getRssi();
  int level = WifiManager.calculateSignalLevel(rssi, 4);
  switch (level) {
    case 0:

代码示例来源:origin: zplesac/android_connectionbuddy

/**
 * Get WiFi signal strength.
 */
private ConnectivityStrength getWifiStrength() {
  WifiManager wifiManager = (WifiManager) configuration.getContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
  WifiInfo wifiInfo = wifiManager.getConnectionInfo();
  if (wifiInfo != null) {
    int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(),
      ConnectionBuddyConfiguration.SIGNAL_STRENGTH_NUMBER_OF_LEVELS);
    switch (level) {
      case 0:
        return new ConnectivityStrength(ConnectivityStrength.POOR);
      case 1:
        return new ConnectivityStrength(ConnectivityStrength.GOOD);
      case 2:
        return new ConnectivityStrength(ConnectivityStrength.EXCELLENT);
      default:
        return new ConnectivityStrength(ConnectivityStrength.UNDEFINED);
    }
  } else {
    return new ConnectivityStrength(ConnectivityStrength.UNDEFINED);
  }
}

代码示例来源:origin: MoMoWait/LeanbackLauncher

this.mConnectivityStatus.mWifiSignalStrength = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), 5);
} else {
  this.mConnectivityStatus.mWifiSignalStrength = 0;

代码示例来源:origin: rockon999/LeanbackLauncher

this.mConnectivityStatus.mWifiSignalStrength = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), 5);
} else {
  this.mConnectivityStatus.mWifiSignalStrength = 0;

相关文章