Android小区ID

3
我想从我的手机中获取cid,我目前使用以下代码来实现这个目标:
GsmCellLocation gsmLocation = (GsmCellLocation)telephonyManager.getCellLocation();
                 int Cid = gsmLocation.getCid();
                 Log.e("#############","current cid is: "+Cid);
                 int lac = gsmLocation.getLac();
                 Log.e("#############","current lac is: "+lac);

这将返回类似于301或6061的内容。

我正在浏览一些示例代码,发现了这个:

/**
 * Seems that cid and lac shall be in hex. Cid should be padded with zero's
 * to 8 numbers if UMTS (3G) cell, otherwise to 4 numbers. Mcc padded to 3
 * numbers. Mnc padded to 2 numbers.
 */
try {
 // Update the current location
 updateLocation(getPaddedHex(cid, cellPadding), getPaddedHex(lac, 4),
   getPaddedInt(mnc, 2), getPaddedInt(mcc, 3));
 strResult = "Position updated!";
} catch (IOException e) {
 strResult = "Error!\n" + e.getMessage();
}

// Show an info Toast with the results of the updateLocation
// call.
Toast t = Toast.makeText(getApplicationContext(), strResult,
  Toast.LENGTH_LONG);
t.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
t.show();}});
}

/**
 * Convert an int to an hex String and pad with 0's up to minLen.
 */
String getPaddedHex(int nr, int minLen) {
  String str = Integer.toHexString(nr);
  if (str != null) {
   while (str.length() < minLen) {
    str = "0" + str;
   }
  }
  return str;
 }

 /**
  * Convert an int to String and pad with 0's up to minLen.
  */
 String getPaddedInt(int nr, int minLen) {
  String str = Integer.toString(nr);
  if (str != null) {
   while (str.length() < minLen) {
    str = "0" + str;
   }
  }
  return str;
 }

GsmCellLocation返回的数字是否正确,或者我需要像示例中展示的那样修改结果?有什么区别吗?我从文档中知道cid可能是-1(未知)或0xffff最大值,0xffff是用于2G或3G网络?

1个回答

2

这段代码实际上并没有改变数字,它只是以十六进制或在左侧添加更多的零来不同地显示它们。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接