无法检索当前单元格的CellID和LAC

时间:2010-10-07 16:59:35

标签: java android cellid

我尝试为当前连接的单元格检索Cid和Lac,但使用

public void GetCid(){
  int CID;
  int LAC;
  GsmCellLocation xXx = new GsmCellLocation();
  CID = xXx.getCid();
  LAC = xXx.getLac();
  Toast output = Toast.makeText(getApplicationContext(), "Base station LAC is "+LAC+"\n" 
  +"Base station CID is " +CID, Toast.LENGTH_SHORT);
  output.show();
}

我得到的唯一值是两个参数的-1值(我在2G上)。可能是我做错了还是有另一种方法来获得当前细胞的Cid和Lac?

1 个答案:

答案 0 :(得分:5)

TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
CellLocation location = telephonyManager.getCellLocation();
GsmCellLocation gsmLocation = (GsmCellLocation) location;
int cellId = gsmLocation.getCid();
int lac = gsmLocation.getLac();