android:NeighboringCellInfo 始终为空!?为什么?
我正在尝试获取有关我的手机可以“看到”自动取款机的邻近小区的信息。到目前为止,一切都很好。我这样做:
telManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
//...
ArrayList<NeighboringCellInfo> neighboringCellList = (ArrayList<NeighboringCellInfo>) telManager.getNeighboringCellInfo();
不幸的是,这个列表一直是空的。即使在不同的地方。我住在柏林,所以我不认为这是因为实际上只有一个可用的单元格!
更新: 我的权限如下所示:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
i'm trying to get info about the neighboring cells my phone can "see" atm. so far so good. i do this like this:
telManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
//...
ArrayList<NeighboringCellInfo> neighboringCellList = (ArrayList<NeighboringCellInfo>) telManager.getNeighboringCellInfo();
unfortunately, this list turns out to be empty all the time. even in different places. i live in berlin, so i don't think it's because there is actually just the one cell available!
update:
my permissions look like this:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经看到了关于同一问题的几个问题,但似乎没有一个问题得到了良好且确定性的解决方案。最常见的建议是确保您拥有正确的权限(我在问题中看到您这样做),有些人说这仅适用于 2G 而不适用于 3G。
看看下面的类似问题。它可能会为您指明一些新方向:
getNeighboringCellInfo() 返回空列表
NeighboringCellInfo 的空问题, CID 和 LAC
在 Android 中获取相邻单元格返回 null
I've seen several questions on the same issue but it seems like none of them got a good and deterministic solution. The most common suggestion is to make sure you have the correct permission (which I see you do in your question) and there are some that say that this only works on 2G and not 3G.
Take a look at the following similar questions. It might point you in some new directions:
getNeighboringCellInfo() returning null list
Null Issue with NeighboringCellInfo, CID and LAC
Get neighboring cell in Android returns null
getNeighboringCellInfo()
在 android 中已弃用。您应该使用getAllCellInfo()
并将其输出保存在List
中,并在 List 的每个元素上使用循环,使用element.isRegistered() 决定哪个是邻居
。NeighboringCells 具有
isRegistered() == false
。getNeighboringCellInfo()
is deprecated in android . You should usegetAllCellInfo()
and save output of that in aList
and using a loop on each element of List decide which is neighbor usingelement.isRegistered()
.NeighboringCells have
isRegistered() == false
.