getCellLocation 返回 null

发布于 2024-09-11 22:56:55 字数 986 浏览 6 评论 0原文

我正在尝试访问当前的小区位置信息。当我 尝试调用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

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

请让我知道我哪里出了问题。

I am trying to access the current cell location information. When I
try to call getCellLocation(), it returns null.

I am unable to reason out this.. the same code works on 1.5 but fails
on 1.6 or 2.1. (Tested on G1 with 1.6 and HTC legend 2.1.)

Can someone help me in correcting this bug? My code is below.

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");
}

Also, I have added the following permissions :

  • ACCESS_FINE_LOCATION
  • ACCESS_COARSE_LOCATION
  • CONTROL_LOCATION_UPDATES

Do I need to add any other permissions?

Kindly let me know where I have gone wrong.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

囚我心虐我身 2024-09-18 22:56:55

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

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

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

getCellLocation() returns null, if current location is not available.

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

Additionally check for the presence of Basebandtype information in your phone settings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文