直接上代码

TelephonyManager mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

// 返回值MCC + MNC

String operator = mTelephonyManager.getNetworkOperator();

int mcc = Integer.parseInt(operator.substring(0, 3));

int mnc = Integer.parseInt(operator.substring(3));

// 中国移动和中国联通获取LAC、CID的方式

GsmCellLocation location = (GsmCellLocation) mTelephonyManager.getCellLocation();

int lac = location.getLac();

int cellId = location.getCid();

Log.i(TAG, " MCC = " + mcc + "\t MNC = " + mnc + "\t LAC = " + lac + "\t CID = " + cellId);

在log信息中就可以看到获取到的lac和cid的值,最后不要忘了在

AndroidManifest.xml添加获取位置信息的权限

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐