getAllCellInfo returns null in android 4.2.1

走远了吗. 提交于 2019-12-17 09:45:59

问题


My Android version is 4.2.1 and I am trying to make use of TelephonyManager.getAllCellInfo() method. In my manifest file I have the ACCESS_COARSE_UPDATES, ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION permissions. However that method returns null.


回答1:


From TelephonyManager.getAllCellInfo() javadoc:

This is preferred over using getCellLocation although for older devices this may return null in which case getCellLocation should be called.

Some sources report that this method is only implemented on CDMA/LTE devices, and other types of devices (including GSM/LTE ones) will return null. Where implemented, it will return only LTE cells.

TelephonyManager.getCellLocation() will return only GSM/UMTS or CDMA cells. It it limited to one cell, the one with which the device is currently registered. This is your safest bet if you are sure your code will only be running on GSM/UMTS or CDMA devices, and if you are only interested in the cell with which the device is currently registered.

To get information about other surrounding cells, use TelephonyManager.getNeighboringCellInfo(). However, it is limited to GSM/UMTS cells. Also, its implementation depends on the radio firmware. Most Samsung devices (and quite a few others) will return an empty list.

Conclusion: getting information about nearby cells on Android is pretty messy business at the moment. You may need to use a combination of all three methods to get the information you want, and even that way, some things may be inaccessible.




回答2:


The following command lists the permissions available on a phone:

adb shell pm list permissions -g

On the Nexus 4 (4.2.2) ACCESS_COARSE_UPDATES permission is not listed.

UPDATE:

When looking though the master branch of the source code there is no reference to ACCESS_COARSE_UPDATES so this appears to be and error in the documentation. In fact the pertinent code only requires ACCESS_COARSE_LOCATION and/or ACCESS_FINE_LOCATION.

Tracing through the following:

  • TelephonyManager
  • ITelephony
  • PhoneInterfaceManager
  • PhoneGlobals
  • PhoneFactory
  • GsmPhone
  • PhoneBase
  • ServiceStateTracker

In ServiceStateTracker:

/**
 * @return all available cell information or null if none.
 */
public List<CellInfo> getAllCellInfo() {
    return null;
}

So it looks like in all cases it will return a null.

Here is a link to a current defect report.




回答3:


The api states the following:

GetAllCellInfo is preferred over using getCellLocation although for older devices this may return null in which case getCellLocation should be called.



来源:https://stackoverflow.com/questions/16541172/getallcellinfo-returns-null-in-android-4-2-1

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