开发者

getCellLocation returns null

开发者 https://www.devze.com 2023-01-08 16:38 出处:网络
I am trying to access the current cell location information. When I try to call getCellLocation(), it returns null.

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号