getCellLocation 返回 null
我正在尝试访问当前的小区位置信息。当我 尝试调用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果当前位置不可用,则 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.