Hi
Is there anyone that have successfully used the telephony manager extention to retrieve the cell ID? If so, please can you share how to do this?
Hi
Is there anyone that have successfully used the telephony manager extention to retrieve the cell ID? If so, please can you share how to do this?
Hi. Thanks for your response. It would seem that LAC and CellID functionality was removed from the extension.
Is there another way to get the Cellid?
I was asking Gemini, if it still is possible to get that information and below is the answer.
I can implement it in July after my vacations
Taifun
Yes, it is still possible to get cell ID and LAC programmatically in Android, but the methods have evolved, and some older APIs are deprecated.
Here's a breakdown:
Example (Conceptual):
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.telephony.CellInfo;
import android.telephony.CellInfoGsm;
import android.telephony.CellInfoLte;
import android.telephony.CellInfoNr;
import android.telephony.CellInfoWcdma;
import android.telephony.TelephonyManager;
import androidx.core.content.ContextCompat;
import java.util.List;
public class CellInfoHelper {
public static void getCellDetails(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager == null) {
// Handle error: TelephonyManager not available
return;
}
if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// Request permissions if not granted
// This would typically be handled in your Activity/Fragment
return;
}
List<CellInfo> cellInfoList = telephonyManager.getAllCellInfo();
if (cellInfoList != null) {
for (CellInfo cellInfo : cellInfoList) {
if (cellInfo.isRegistered()) { // Check if this is the serving cell
if (cellInfo instanceof CellInfoGsm) {
CellInfoGsm cellInfoGsm = (CellInfoGsm) cellInfo;
int cid = cellInfoGsm.getCellIdentity().getCid();
int lac = cellInfoGsm.getCellIdentity().getLac();
System.out.println("GSM Cell - CID: " + cid + ", LAC: " + lac);
} else if (cellInfo instanceof CellInfoWcdma) {
CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) cellInfo;
int cid = cellInfoWcdma.getCellIdentity().getCid();
int lac = cellInfoWcdma.getCellIdentity().getLac();
System.out.println("WCDMA Cell - CID: " + cid + ", LAC: " + lac);
} else if (cellInfo instanceof CellInfoLte) {
CellInfoLte cellInfoLte = (CellInfoLte) cellInfo;
int ci = cellInfoLte.getCellIdentity().getCi();
int tac = cellInfoLte.getCellIdentity().getTac();
System.out.println("LTE Cell - CI: " + ci + ", TAC: " + tac);
} else if (cellInfo instanceof CellInfoNr) {
CellInfoNr cellInfoNr = (CellInfoNr) cellInfo;
long nci = cellInfoNr.getCellIdentity().getNci();
int tac = cellInfoNr.getCellIdentity().getTac();
System.out.println("NR Cell (5G) - NCI: " + nci + ", TAC: " + tac);
}
}
}
}
}
}
Important Considerations:
In summary, while the older GsmCellLocation methods are deprecated, the TelephonyManager.getAllCellInfo() API provides a robust and modern way to retrieve cell ID and LAC (or their equivalents) programmatically on Android devices, provided you have the necessary location permissions.
Much obliged