TelephonyManager [Android] 类型未定义方法 getAllCellInfo()

The method getAllCellInfo() is undefined for the type TelephonyManager [Android]

使用以下代码,我正在尝试获取可用的单元格信息:

import android.telephony.CellInfo;

TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService( context.TELEPHONY_SERVICE );
List<CellInfo> cellList = telephonyManager.getAllCellInfo();

知道方法 getAllCellInfo() 和 class CellInfo 是在 API 级别 17 中引入的,我设置了 android:minSdkVersion="17" 在 AndroidManifest.xml 文件中。

但是,在 Eclipse 中,我收到一条错误消息: 无法解析导入android.telephony.CellInfo并且 TelephonyManager 类型未定义方法 getAllCellInfo()

我已经尝试清理、关闭 Eclipse 并重建我的项目,但我仍然遇到这些错误。我不知道为什么 Eclipse 不能识别这些声明

感谢您的帮助。

编辑: 许可 android.permission.ACCESS_COARSE_LOCATION 也包含在 AndroidManifest.xml 文件中。但问题仍然存在。

检查您的 project.properties 文件并查看您正在构建的目标。它应该看起来像这样:

target=Google Inc.:Google APIs:17

这是我手头上的一个旧项目,正在为 API 17 年(Google APIs.)构建

您还可以进入项目属性并检查 UI 中的目标。该设置对应于此文件,是 Eclipse 用来构建的对象,而不是清单。清单在平台运行时用于了解在框架中启用哪些兼容模式。