2

我正在尝试访问当前的小区位置信息。当我尝试调用getCellLocation()时,它会返回null

我无法推理出这一点。相同的代码在 1.5 上有效,但在 1.6 或 2.1 上失败。(在 G1 上测试 1.6 和 HTC Legend 2.1。)

有人可以帮我纠正这个错误吗?我的代码如下。

TelephonyManager tMgr = (TelephonyManager)
getSystemService(TELEPHONY_SERVICE);
outputView = (TextView) findViewById(R.id.output);

outputView.append("Device type:" + tMgr.getPhoneType() + "\n");

GsmCellLocation gsmCellLocation = (GsmCellLocation) tMgr.getCellLocation();
if (gsmCellLocation != null) {
    String mCellId = "" + gsmCellLocation.getCid();
    String mLAC = "" + gsmCellLocation.getLac();
    Log.d("SDKService", "Cell Id: " + mCellId + " LAC: " + mLAC);
    outputView.append("Cell Id: " + mCellId + " LAC: " + mLAC + "\n");
}

此外,我还添加了以下权限:

  • ACCESS_FINE_LOCATION
  • ACCESS_COARSE_LOCATION
  • CONTROL_LOCATION_UPDATES

我需要添加任何其他权限吗?

请让我知道我哪里出错了。

4

1 回答 1

0

如果当前位置不可用,getCellLocation() 将返回 null。

http://developer.android.com/reference/android/telephony/TelephonyManager.html#getCellLocation%28%29

此外,检查手机设置中是否存在基带类型信息。

于 2012-06-11T13:01:51.377 回答