5

目标:获取特定类型连接(我实际使用的连接)的信息(信号强度)。

问题:我不确定到底是什么reperesentCellInfo以及如何从中提取信息getAllCellInfo

问题:

1) 来自安卓开发者网站

CellInfo:来自某个时间点的不可变单元格信息。

这是什么意思?

2) 我想了解我使用的是 wcdma、umts、gsm 还是 lte。我在这里找到了一段使用getAllCellInfo的代码片段,低于我的改编版本以获取信号强度

  for (final CellInfo info : telephonyManager.getAllCellInfo()) {

            if (info instanceof CellInfoGsm) {

                final CellSignalStrengthGsm gsm = ((CellInfoGsm) info).getCellSignalStrength();
                if(gsm.getLevel() >= localMaxSignalStrength)
                     localMaxSignalStrength = gsm.getLevel();
                Toast.makeText(getApplicationContext(), "gsm rssi" + localMaxSignalStrength, Toast.LENGTH_LONG).show();

            } else if (info instanceof CellInfoWcdma) {

                final CellSignalStrengthWcdma cdma = ((CellInfoWcdma) info).getCellSignalStrength();
                if(cdma.getLevel() >= localMaxSignalStrength)
                    localMaxSignalStrength = cdma.getLevel();
                Toast.makeText(getApplicationContext(), "wcdma rssi" + localMaxSignalStrength, Toast.LENGTH_LONG).show();

            } else if (info instanceof CellInfoLte) {

                final CellSignalStrengthLte lte = ((CellInfoLte) info).getCellSignalStrength();
                if(lte.getLevel() >= localMaxSignalStrength)
                    localMaxSignalStrength = lte.getLevel();
                Toast.makeText(getApplicationContext(), "lte rssi" + localMaxSignalStrength, Toast.LENGTH_LONG).show();

现在从我在 Android 开发者网站上读到的内容

getAllCellInfo():返回来自设备上所有无线电的所有观察到的小区信息,包括主小区和相邻小区。调用此方法不会触发对 onCellInfoChanged() 的调用,也不会更改调用 onCellInfoChanged() 的速率。

该列表可以包括任意组合的一个或多个CellInfoGsm、CellInfoCdma、CellInfoLte 和 CellInfoWcdma 对象。

所以这意味着它getAllCellInfo()不会只返回一种连接信息,但它们可以混合使用。我想了解我的手机是在使用所有退回的手机还是只使用其中一个(在后一种情况下如何找到我正在使用的手机)。

4

0 回答 0