1. 程式人生 > >android中獲取lac和cid的方法

android中獲取lac和cid的方法

直接上程式碼

 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新增獲取位置資訊的許可權
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />