문제

I tried to retrieve Cid and Lac for currently connected cell, but using

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

The only thing I get is -1 value for both parameters (I am on 2G). May be I do something wrong or there is another way to get Cid and Lac of current cell?

도움이 되었습니까?

해결책

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