解决方法
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()); } }
不要忘记设置ACCESS_COARSE_LOCATION或ACCESS_FINE_LOCATION,否则您将获得SecurityExceptions.
例如,将以下内容添加到< manifest>应用清单中的元素:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>