getAllCellInfo() returns an empty list in Huawei Honor 7

给你一囗甜甜゛ 提交于 2019-12-22 09:27:29

问题


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?


回答1:


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");
    }



回答2:


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



来源:https://stackoverflow.com/questions/43886256/getallcellinfo-returns-an-empty-list-in-huawei-honor-7

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