Android获取基站信息,高手请进 在Android中 怎么获取基站信息。高分酬谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 TelephonyManager.getCellLocation();得到GsmCellLocation 这个对象有你要的 android获取cellid比较简单,你可以试试获取邻接基站id,这样三角定位更准确些 1、首先 获取服务 telephonyManager =(TelephonyManager) getSystemService(TELEPHONY_SERVICE);2、注册监听器 telephonyManager.listen(celllistener, PhoneStateListener.LISTEN_CELL_LOCATION); // 基站位置的变化3、编写监听代码 public PhoneStateListener celllistener = new PhoneStateListener() { @Override public void onCellLocationChanged(CellLocation location) { super.onCellLocationChanged(location); // 判断 location的类型 是GsmCellLocation 还是 CdmaCellLocation // 最后 根据你的业务 需求 实现你的代码 } }; 基站是什么?CELL/NODEB/RNC/CN你要的是哪个? 我在android2.2以上的版本获取GsmCellLocation的时候是null值啊 telephone = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);cellLocation = (GsmCellLocation)telephone.getCellLocation();cellLocation在android2.2以上的版本中运行为null怎么解决啊 你系统的设置中开启了允许network定位没 在哪里设置啊?我android2.2一下的版本都可以啊? settings-location & security 中第一项你勾选了吗 请大家能给我一个Demo例子,获取基站的编号和信号强度以及时间的偏移度十分感谢! TelephonyManager tm;tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); GsmCellLocation gcl = (GsmCellLocation) tm.getCellLocation(); int cid = gcl.getCid(); int lac = gcl.getLac(); int mcc = Integer.valueOf(tm.getNetworkOperator().substring(0,3)); int mnc = Integer.valueOf(tm.getNetworkOperator().substring(3,5)); try { // 组装JSON查询字符串 JSONObject holder = new JSONObject(); holder.put("version", "1.1.0"); holder.put("host", "maps.google.com"); // holder.put("address_language", "zh_CN"); holder.put("request_address", true); JSONArray array = new JSONArray(); JSONObject data = new JSONObject(); data.put("cell_id", cid); // 25070 data.put("location_area_code", lac);// 4474 data.put("mobile_country_code", mcc);// 460 data.put("mobile_network_code", mnc);// 0 array.put(data); holder.put("cell_towers", array); // 创建连接,发送请求并接受回应 DefaultHttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://www.google.com/loc/json"); StringEntity se = new StringEntity(holder.toString()); post.setEntity(se); HttpResponse resp = client.execute(post); HttpEntity entity = resp.getEntity(); BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent())); StringBuffer sb = new StringBuffer(); String result = br.readLine(); while (result != null) { sb.append(result); result = br.readLine(); } String message=sb.toString();这个message就是基站里包含的信息了,你再解析一下就可以了 可以看看rexsee的源码。rexsee现在开源了。 android 调用webservices时传泛型参数 android 调用webservice问题 WebView获取 网页内容 求高人指点notepad里的一些东西 Android如何获得图片的路径 Android文字方向设置 Android CPU优化 qq授权和空间分享 这个在android怎么实现啊????? Android8.0系统的手机上drawBitmap会变得非常卡 关于viewpager的问题 RadioGroup问题!!(求助)
得到GsmCellLocation 这个对象有你要的
public PhoneStateListener celllistener = new PhoneStateListener() {
@Override
public void onCellLocationChanged(CellLocation location) {
super.onCellLocationChanged(location);
// 判断 location的类型 是GsmCellLocation 还是 CdmaCellLocation
// 最后 根据你的业务 需求 实现你的代码 }
};
CELL/NODEB/RNC/CN你要的是哪个?
cellLocation = (GsmCellLocation)telephone.getCellLocation();
cellLocation在android2.2以上的版本中运行为null怎么解决啊
十分感谢!
tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
GsmCellLocation gcl = (GsmCellLocation) tm.getCellLocation();
int cid = gcl.getCid();
int lac = gcl.getLac();
int mcc = Integer.valueOf(tm.getNetworkOperator().substring(0,3));
int mnc = Integer.valueOf(tm.getNetworkOperator().substring(3,5));
try {
// 组装JSON查询字符串
JSONObject holder = new JSONObject();
holder.put("version", "1.1.0");
holder.put("host", "maps.google.com");
// holder.put("address_language", "zh_CN");
holder.put("request_address", true);
JSONArray array = new JSONArray();
JSONObject data = new JSONObject();
data.put("cell_id", cid); // 25070
data.put("location_area_code", lac);// 4474
data.put("mobile_country_code", mcc);// 460
data.put("mobile_network_code", mnc);// 0
array.put(data);
holder.put("cell_towers", array);
// 创建连接,发送请求并接受回应
DefaultHttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://www.google.com/loc/json");
StringEntity se = new StringEntity(holder.toString());
post.setEntity(se);
HttpResponse resp = client.execute(post);
HttpEntity entity = resp.getEntity();
BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
StringBuffer sb = new StringBuffer();
String result = br.readLine();
while (result != null) {
sb.append(result);
result = br.readLine();
}
String message=sb.toString();
这个message就是基站里包含的信息了,你再解析一下就可以了