Frage

Ich habe versucht, für aktuell verbundenen Zelle Cid und Lac abzurufen, sondern mit

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

Das einzige, was ich bekommen ist -1 Wert für beide Parameter (ich bin auf 2G). sein kann, mache ich etwas falsch oder gibt es eine andere Art und Weise Cid und Lac des aktuellen Zelle zu bekommen?

War es hilfreich?

Lösung

TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
CellLocation location = telephonyManager.getCellLocation();
GsmCellLocation gsmLocation = (GsmCellLocation) location;
int cellId = gsmLocation.getCid();
int lac = gsmLocation.getLac();
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top