我试图检索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?

有帮助吗?

解决方案

TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
CellLocation location = telephonyManager.getCellLocation();
GsmCellLocation gsmLocation = (GsmCellLocation) location;
int cellId = gsmLocation.getCid();
int lac = gsmLocation.getLac();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top