gpt4 book ai didi

android - 在 Android Q API 29 中使用 getNeighboringCellInfo() 给出错误 "Cannot resolve method"而不是弃用警告

转载 作者:搜寻专家 更新时间:2023-11-01 09:19:56 39 4
gpt4 key购买 nike

我有一段代码使用 android.telephony.TelephonyManager 中的 getNeighboringCellInfo() 方法,它在 Android Studio 中运行良好,compileSdkVersion 设置为 28,但是当我将 compileSdkVersion 设置为 29 时,我收到错误“无法解析方法”而不是弃用警告因为这个方法在API 29中被移除了。结果是项目无法构建。

有人知道如何解决这个问题吗?

TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
List<NeighboringCellInfo> n=telephonyManager.getNeighboringCellInfo();

最佳答案

NeighboringCellInfo 类在 Android Q 中被弃用(因此不鼓励但仍然可以使用),但是 TelephonyManager.getNeighboringCellInfo() 显然之前被弃用了,并且 已从 Android Q 中移除。它不再出现在 Android 文档中。下面引用来自a related bug on the Android Issue Tracker的官方回复:

"A @removed method is not intended to be available in the sdk. As mentioned in the docs, we suggest to use getAllCellInfo instead.

We @deprecated this function 2 years ago. The alternative (getAllCellInfo) function was created 7 years ago. It should be available on the older devices you need to support."

官方提供的解决方案on a duplicate issue就是使用反射:

The recommended approach would be to detect the API version in use and use the new method where available, otherwise to use reflection to access the old method if needed.

关于android - 在 Android Q API 29 中使用 getNeighboringCellInfo() 给出错误 "Cannot resolve method"而不是弃用警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56984281/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com