我正在制作一个应用程序,我必须得到lac和cell id。我正在使用
private PhoneStateIntentReceiver mPhoneStateReceiver;
ServiceState state = mPhoneStateReceiver.getServiceState();
int cid = state.getCid();
int lac = state.getLac();
及其给出的错误,即PhoneStateIntentReceiver无法解析为类型和getcellid和getlac也给出了errorthat getcellid未定义为ServiceState
任何帮助将不胜感激。
答案 0 :(得分:1)
用它来获取cid和Lac
final TelephonyManager telephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (telephony.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
final GsmCellLocation location = (GsmCellLocation) telephony.getCellLocation();
if (location != null) {
msg.setText("LAC: " + location.getLac() + " CID: " + location.getCid());
}
}
获得许可
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>