Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CellIdentityLite getCi()在android中返回-1_Android_Mobile_Cellid_Lte - Fatal编程技术网

CellIdentityLite getCi()在android中返回-1

CellIdentityLite getCi()在android中返回-1,android,mobile,cellid,lte,Android,Mobile,Cellid,Lte,我有一个方法返回LTE设备的小区id,但在某些设备上返回-1。方法如下: public int getCellId() { int cellId = Integer.MAX_VALUE; CellInfo cellInfo = null; List<CellInfo> allCellInfo = telephonyManager.getAllCellInfo(); if(allCellInfo!= null && allCell

我有一个方法返回LTE设备的小区id,但在某些设备上返回-1。方法如下:

    public int getCellId() {
    int cellId = Integer.MAX_VALUE;
    CellInfo cellInfo = null;
    List<CellInfo> allCellInfo = telephonyManager.getAllCellInfo();
    if(allCellInfo!= null && allCellInfo.size()>0)
        cellInfo = allCellInfo.get(0);
    if (cellInfo instanceof CellInfoLte) {
        CellInfoLte cellInfoLte = (CellInfoLte) cellInfo;
        if (cellInfoLte != null) {
            cellId = cellInfoLte.getCellIdentity().getCi();
        }
    }
    return cellId;
}
public int getCellId(){
int cellId=Integer.MAX_值;
CellInfo CellInfo=null;
List allCellInfo=telephonyManager.getAllCellInfo();
if(allCellInfo!=null&&allCellInfo.size()>0)
cellInfo=allCellInfo.get(0);
if(CellInfoLte的cellInfo实例){
CellInfoLte CellInfoLte=(CellInfoLte)cellInfo;
if(cellInfoLte!=null){
cellId=cellInfoLte.getCellIdentity().getCi();
}
}
返回细胞;
}

您已经正确地实现了它,不幸的是,并非所有制造商都正确地实现了所有Android API,尤其是在电话领域。有时所有LTE值也将为-1,有时仅为CI。

谢谢您的回答。我使用的是三星Core Prime和LG Spirit,大多数时候它返回的是有效的手机Id,但在某些情况下返回的是-1。这可能是什么原因?你能给我一些参考资料吗?我的主要参考资料来自一个发布了超过300k下载量的signal应用程序的个人经验。基本上,我不相信大多数电话文档返回的值。此外,即使公共API有时返回-1,系统工程屏幕也可以显示正确的值。在一种情况下,由于用户能够在强制非LTE模式后获得LTE值,然后返回到LTE模式。我还在研究其他的解决办法。