No se puede recuperar CellID y ALC para la celda actual
Pregunta
He intentado recuperar Cid y Lac de celda actualmente conectadas, pero utilizando
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();
}
Lo único que consigo es -1 valor para ambos parámetros (Estoy en 2G). Puede ser que hago algo mal o hay otra manera de conseguir Cid y Lac de celda actual?
Solución
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
CellLocation location = telephonyManager.getCellLocation();
GsmCellLocation gsmLocation = (GsmCellLocation) location;
int cellId = gsmLocation.getCid();
int lac = gsmLocation.getLac();
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow