我正在尝试使用 Android 识别 3G 中的相邻小区位置,这是通过 getNeighboringCellInfo() 获得的。当手机工作在 GSM 模式时,我可以使用 getCid() 和 getLac() 来获取 CellID 和 LAC,但是对于 3G,我只能使用 getPsc(),我不太确定它是否足够来识别一个细胞。
谁能告诉我是否可以获得相邻小区的 CellID + LAC?如果这不可能,我如何使用 PSC 代码来识别单元格?
在 UMTS 中,PSC 是一种本地小区标识符。它是“本地”唯一的,因为所有相邻小区以及这些小区的所有邻居都保证具有与当前小区不同的 PSC。这也意味着您永远不会遇到两个具有相同 PSC 的相邻单元。但是,很可能有位于该国不同地区的具有相同 PSC 的小区。
UMTS 小区的 NeighboringCellInfo 将仅设置 PSC,而所有其他字段(MCC、MNC、LAC、CID)将无效。找出这些参数的唯一方法是存储您遇到的每个单元的所有字段(MCC、MNC、LAC、CID 以及 PSC),然后在获得“未知”PSC 时在存储的数据中查找它。(您需要过滤服务小区的邻居,因为 PSC 只是本地唯一 ID,而不是全局唯一 ID)。
作为替代方案,一个小区的 PSC 以及它的一个邻居的 MCC/MNC/LAC/CID 元组也是您可以使用的全球唯一 ID。但是请注意,每个小区都会有多个这样的标识符(每个邻居一个)。
我可以获得相邻小区的 cid 和 rssi。所以你试试这个代码,它只适用于物理材料(不要使用模拟器)。在这里,您使用 textview 创建您的 android xml。;-)
package app.tel;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.NeighboringCellInfo;
import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;
import android.widget.TextView;
public class TelephActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView textGsmCellLocation = (TextView)findViewById(R.id.gsmcelllocation);
TextView textMCC = (TextView)findViewById(R.id.mcc);
TextView textMNC = (TextView)findViewById(R.id.mnc);
TextView textCID = (TextView)findViewById(R.id.cid);
//retrieve a reference to an instance of TelephonyManager
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
GsmCellLocation cellLocation = (GsmCellLocation)telephonyManager.getCellLocation();
String networkOperator = telephonyManager.getNetworkOperator();
String mcc = networkOperator.substring(0, 3);
String mnc = networkOperator.substring(3);
textMCC.setText("mcc: " + mcc);
textMNC.setText("mnc: " + mnc);
int cid = cellLocation.getCid();
//int lac = cellLocation.getLac();
textGsmCellLocation.setText(cellLocation.toString());
textCID.setText("gsm cell id: " + String.valueOf(cid));
TextView Neighboring = (TextView)findViewById(R.id.neighboring);
List<NeighboringCellInfo> NeighboringList = telephonyManager.getNeighboringCellInfo();
String stringNeighboring = "Neighboring List- Lac : Cid : RSSI\n";
for(int i=0; i < NeighboringList.size(); i++){
String dBm;
int rssi = NeighboringList.get(i).getRssi();
if(rssi == NeighboringCellInfo.UNKNOWN_RSSI){
dBm = "Unknown RSSI";
}else{
dBm = String.valueOf(-113 + 2 * rssi) + " dBm";
}
stringNeighboring = stringNeighboring
+ String.valueOf(NeighboringList.get(i).getLac()) +" : "
+ String.valueOf(NeighboringList.get(i).getCid()) +" : "
+ String.valueOf(NeighboringList.get(i).getPsc()) +" : "
+ String.valueOf(NeighboringList.get(i).getNetworkType()) +" : "
+ dBm +"\n";
}
Neighboring.setText(stringNeighboring);
}
}
有时,当同一提供商的多个 CID 共享同一塔/站点时,用于增加容量并在同一方向上传输时,具有相同的 PSC。因此,在这些情况下,您可以使用 PSC 来识别站点和波束方向,而不是 CID。