4

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

我的代码: 目录:
在此处输入图像描述
在此处输入图像描述

我检查了其他人的问题: getAllCellInfo 在 android 4.2.1 中返回 nullAndroid getAllCellInfo() 返回 null

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

网络单元信息精简版 NetMonster
在此处输入图像描述

在此处输入图像描述

有人有这方面的信息吗?

4

4 回答 4

2

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

首先让我解释一下问题:

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

然后:

  • 我发现此页面提到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? // ... }

  • 我找到了这个页面(Android Studio 无法识别 LG G4)。根据亨利托马斯的解决方案,我下载了LG驱动程序;最后,Android Studio 重新设计了 LG K8 手机。

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

所以,我的发现:

  • getAllCellInfo不适用于某些Dual Sim Huawei/Honor 手机

  • 使用LG 驱动程序,以便 Android Studio 识别 LG 手机。

于 2020-01-21T15:21:33.167 回答
2

在没有单元格的情况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");
    }
于 2017-08-31T13:40:35.107 回答
0

实现 CellInfo() 的方法有很多。

某些设备不支持getAllCellInfo()

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

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

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

于 2018-10-25T10:07:54.313 回答
0

可能为时已晚,但是当您针对 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()
                        }
                    })
            }
于 2021-02-08T12:57:46.613 回答