NeighboringCellInfo,CID和LAC的空问题

有一段时间我试图获得近基站的CellID和LAC。 不幸的是我无法做到这一点。 第一种选择是使用:

GsmCellLocation xXx = new GsmCellLocation(); CID = xXx.getCid(); LAC = xXx.getLac(); Toast output = Toast.makeText(getApplicationContext(), "Base station LAC is "+LAC+"\n" +"Base station CID is " +CID, Toast.LENGTH_SHORT); output.show(); 

但在这种情况下,我收到-1值(据我所知,这意味着它不是GSM,但当我用isGSM检查它显示“真”)。 我发现网上冲浪的另一种方式(我稍微更新了一下)

 public void GetID(){ List neighCell = null; TelephonyManager telManager = ( TelephonyManager )getSystemService(Context.TELEPHONY_SERVICE); neighCell = telManager.getNeighboringCellInfo(); for (int i = 0; i < neighCell.size(); i++) { try { NeighboringCellInfo thisCell = neighCell.get(i); int thisNeighCID = thisCell.getCid(); int thisNeighRSSI = thisCell.getRssi(); log(" "+thisNeighCID+" - "+thisNeighRSSI); } catch (NumberFormatException e) { e.printStackTrace(); NeighboringCellInfo thisCell = neighCell.get(i); log(neighCell.toString()); } } } 

但在这种情况下,应用程序只是在按下执行按钮后崩溃。 Eclipse没有显示任何错误。 可能有人有任何想法如何解决我的问题?

Logcat说:10-05 22:53:27.923:ERROR / dalvikvm(231):无法打开堆栈跟踪文件’/data/anr/traces.txt’:权限被拒绝

使用权限:

        

可能是问题是我忘了包括:

 TelephonyManager telManager = ( TelephonyManager )getSystemService(Context.TELEPHONY_SERVICE); 

更新。 我从上面包括一行,崩溃消失但现在按下按钮后没有任何反应。 更新了源代码。

您是否validation过您在清单文件中设置了正确的权限?

TelephonyManager需要许多权限,具体取决于您使用的API。 大多数API需要READ_PHONE_STATE ,此外getNeighboringCellInfo的文档提到了ACCESS_COARSE_UPDATES ,但是我认为这可能是一个doc错误,你实际上需要ACCESS_COARSE_LOCATION ,它被记录为“允许应用程序访问粗略的(例如,Cell-ID, WiFi)位置“

cellid实现因移动设备而异,因为这些function被认为是可选的。 例如:

三星(所有设备):getNeigbouringCells()根本不受支持,并且总是返回一个空列表。

根据这个: http : //wiki.opencellid.org/wiki/Android_library

有同样的问题。 尝试在分叉线程(非UI)上运行相邻单元格的查询。 至少我遇到的问题是锤头安卓检查,并立即返回null留下logcat中的日志:

 @PhoneInterfaceManager: getNeighboringCellInfo RuntimeException - This method will deadlock if called from the main thread.