getAllCellInfo() returns an empty list in Huawei H

2019-05-03 11:10发布

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:
enter image description here
Catlog: enter image description here

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
enter image description here
NetMonster
enter image description here

Anybody has any information about this?

2条回答
我只想做你的唯一
2楼-- · 2019-05-03 11:51

There are many ways to achieve CellInfo().

Some devices Doesn't support getAllCellInfo().

  1. Try telephonyManager.getNeighboringCellInfo() (This method is deprecated but still supported by some devices)

  2. 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).

查看更多
孤傲高冷的网名
3楼-- · 2019-05-03 11:59

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");
    }
查看更多
登录 后发表回答