【问题标题】:getAllCellInfo() returns an empty list in Huawei Honor 7getAllCellInfo() 在华为荣耀7中返回一个空列表
【发布时间】:2017-05-10 07:37:35
【问题描述】:

我有一个获取手机信号塔信息的安卓应用程序。我使用这个 getAllCellInfo() 来获取主小区和相邻小区的信息。我在 manifest.xml 中包含了 ACCESS_COARSE_LOCATION 权限,并在运行时请求该权限。 它适用于其他手机,但在华为荣耀 7 中,该函数返回一个空列表。

我的代码:

目录:

我检查了其他人的问题: getAllCellInfo returns null in android 4.2.1Android getAllCellInfo() returns null

从一个问题,我认为华为手机不支持getAllCellInfo(),直到我安装了Network Cell Info LiteNetMonster,并且应用程序似乎可以获取华为荣耀7中的手机信息:

网络小区信息精简版

NetMonster

有人知道这方面的信息吗?

【问题讨论】:

  • 嘿 phuwin,你找到解决这个问题的方法了吗?我也遇到了同样的问题
  • @Royz 不是真的...
  • 嗨,普温!你找到解决方案了吗?为什么 NetworkCellInfo 运行良好?

标签: android telephonymanager cellinfo


【解决方案1】:

getAllCellInfo() 中没有单元格时,我使用getCellLocation() 来获取primaryCellId 和 trackingAreaCode,如下所示:

    Log.d(TAG, "updateCurrentCell: can't find any cells with getAllCellInfo");
    CellLocation primaryLocation = telephonyManager.getCellLocation();
    if (primaryLocation != null) {
        int primaryCellId = Integer.parseInt(primaryLocation.toString().split(",")[1]);
        int trackingAreaCode = Integer.parseInt(primaryLocation.toString().split(",")[0].replace("[", ""));
    } else {
        Log.d(TAG, "updateCurrentCell: not even with getCellLocation");
    }

【讨论】:

  • 当我打印 primaryLocation 对象时,我得到以下行:'primaryLocation: GsmCellLocation:[...]'
【解决方案2】:

虽然来晚了,但可能对遇到相同问题的其他人有所帮助。

首先让我解释一下问题:

  • 我试图在我的应用中使用 getAllCellInfo()
  • 该应用在 Android 模拟器(单模拟器)上运行流畅。
  • 然后我在运行 Android 6.0 的“Dual Sim,Huawei CAM-L21”和运行 Android 4.4.2 的“Dual Sim,Honor 3c”上也进行了尝试.但在华为上,getAllCellInfo() 返回 Empy List,而在荣耀上返回 null
  • 我尝试使用“LG K8”。但 Android Studio 无法识别手机。我在 LG 网站上找不到手机驱动程序(适用于 Windows)!所以我安装了一些通用的 ADB 驱动程序。很遗憾,Android Studio 无法再次识别该手机。
  • 该应用在一些单卡华为和三星手机上运行良好;我不记得模型了!

那么:

  • 我发现this page 提到getAllCellInfo 可能无法在某些手机上使用:

    private void getAllCellInfo(List<CellInfo> cellInfo) { // only for registered cells is returned identify // SlimKat in Galaxy Nexus - returns null :-/ // Honor 7 - returns empty list (not null), Dual SIM? // ... }

  • 我找到了this page (LG G4 not recognised by Android Studio)。根据Henry Thomas's solution,我下载了LG驱动;最后,Android Studio 重新设计了 LG K8 手机。

  • 最后,我的应用可以在双卡手机上运行。

所以,我的发现:

  • getAllCellInfo 不适用于某些华为/荣耀双卡手机

  • 使用LG drivers,以便Android Studio 识别LG 手机。

【讨论】:

    【解决方案3】:

    CellInfo()的实现方式有很多种。

    某些设备不支持 getAllCellInfo()

    1. 尝试 telephonyManager.getNeighboringCellInfo()(此方法已弃用,但某些设备仍支持)

    2. 要从该设备获取 cellinfo,请尝试在 SDK(API) 21 上构建您的应用。(不推荐)。

    (能够显示所有信息的应用很可能是在 API 21 或更低版本上构建和定位的)。

    【讨论】:

      【解决方案4】:

      可能为时已晚,但当您面向 Android 10 或更高版本时,您应该调用 requestCellInfoUpdate

      val subscriptionManager = getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE)
                          as SubscriptionManager
                  for (subs in subscriptionManager.activeSubscriptionInfoList) {
                      val telephonyManager =
                          (getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager)
                              .createForSubscriptionId(subs.subscriptionId)
                      telephonyManager.requestCellInfoUpdate(mainExecutor,
                          object : TelephonyManager.CellInfoCallback() {
                              override fun onCellInfo(cellInfo: MutableList<CellInfo>) {
                                  println("updated_cells_count: ${cellInfo.size}")
                              }
      
                              override fun onError(errorCode: Int, detail: Throwable?) {
                                  super.onError(errorCode, detail)
                                  println("updated_cells_error:\n")
                                  detail?.printStackTrace()
                              }
                          })
                  }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-03
        • 1970-01-01
        • 2021-02-03
        • 1970-01-01
        相关资源
        最近更新 更多