Get neighboring cell in Android returns null

半城伤御伤魂 提交于 2019-12-02 11:51:57

问题


I'm trying to get the neighbouring cell info in Android but the function getNeighboringCellInfo() always return null.

I used the following code :

protected void getCellInfo() {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    List<NeighboringCellInfo> neighborCells = telephonyManager.getNeighboringCellInfo();
    if (neighborCells == null) {
        OutUtils.debug("no neighbor cells");
    } else {
        ...
    }
}

The context variable is from a Service class.

My AndroidManifest.xml permission

<uses-permission android:name="android.permission.INTERNET"/>
<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_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

I tried with and without enabling the "Use 2G networks" option in Android.

Any idea ? Thanks


回答1:


I think, maybe you haven't set all necessary permissions in Manifest. look here Null Issue with NeighboringCellInfo, CID and LAC

If you think you have them, put the manifest in the question, too, please.




回答2:


If you can run logcat, try running logcat -b radio. If you are lucky, the RIL code will be spitting out debug messages, showing the actual request to the modem for the neighboring cell info. It could well be that the modem is just returning an empty list. If this is the case, it has nothing to do with permissions, and there is not much you can to fix it.




回答3:


The cellid implementation varies from mobile device to mobile device since these features are considered to be optional. for example:

Samsung (all devices): getNeigbouringCells () is not supported at all and always returns an empty list.

according to this: http://wiki.opencellid.org/wiki/Android_library

and this: https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&groupby=&sort=&id=24306



来源:https://stackoverflow.com/questions/9096754/get-neighboring-cell-in-android-returns-null

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!