I am having an android application that fetches information of cell towers. I use this getAllCellInfo() to fetch info of a primary cell and neighbour cells. I included the ACCESS_COARSE_LOCATION permission to manifest.xml and make a request for the permission in runtime.
It works in other phones but in Huawei Honor 7, the function returns an empty list.
My code:
Catlog:
I have checked other people questions: getAllCellInfo returns null in android 4.2.1 and Android getAllCellInfo() returns null.
From a question, I thought for Huawei phones, they don't support getAllCellInfo() until I installed Network Cell Info Lite and NetMonster, and it seems that the applications can fetch the cell information in Huawei Honor 7:
Network Cell Info Lite
NetMonster
Anybody has any information about this?
For a little work around when there is no cell in getAllCellInfo()
, I use getCellLocation()
to get the primaryCellId and trackingAreaCode like this:
Log.d(TAG, "updateCurrentCell: can't find any cells with getAllCellInfo");
CellLocation primaryLocation = telephonyManager.getCellLocation();
if (primaryLocation != null) {
int primaryCellId = Integer.parseInt(primaryLocation.toString().split(",")[1]);
int trackingAreaCode = Integer.parseInt(primaryLocation.toString().split(",")[0].replace("[", ""));
} else {
Log.d(TAG, "updateCurrentCell: not even with getCellLocation");
}
There are many ways to achieve CellInfo().
Some devices Doesn't support getAllCellInfo().
Try telephonyManager.getNeighboringCellInfo() (This method is deprecated but still supported by some devices)
To get cellinfo from that device try by building your App on SDK(API) 21.(Not recommended).
( App which are able to show all information are high likely builded and targeted on API 21 or less).
来源:https://stackoverflow.com/questions/43886256/getallcellinfo-returns-an-empty-list-in-huawei-honor-7