Telephonymanager getAllCellsInfo returns 错误的注册单元计数

Telephonymanager getAllCellsInfo returns wrong registered cells count

我在 phone 上有两张有效的 SIM 卡。但是getAllCellsInfo returns 只有一个注册单元格。这怎么会发生?我应该怎么做才能解决它?

SubscriptionManager.geAllSubscriptionsInfoList() returns 2 个值。

我在 phone 上更换 SIM 卡时看到了这种情况。例如,您可以在不 phone 重新启动的情况下添加第二张 SIM 卡,但是 TelephonyManager 会继续为您提供唯一一个已注册的 CellInfo,直到您重新启动 phone。

我正在搜索以编程方式在不 phone 重新启动的情况下更新 TelephonyManager 中的数据。可能吗?

当您定位到 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()
                        }
                    })
            }