android运营商相关信息获取代码收集

1,手机卡运营商获取:

private  String getSimOperator(Context context) {
        String opeName = "";
        TelephonyManager teleManager= (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String opeNum = teleManager.getSimOperator();
        if ("46001".equals(opeNum ) || "46006".equals(opeNum ) || "46009".equals(opeNum )) {
            opeType = "中国联通";
        } else if ("46000".equals(opeNum ) || "46002".equals(opeNum ) || "46004".equals(opeNum ) || "46007".equals(operator)) {
            opeType = "中国移动";
        } else if ("46003".equals(opeNum ) || "46005".equals(opeNum ) || "46011".equals(opeNum )){
            opeType = "中国电信";
        }
        return opeType;
    }

2,获取移动网络类型

private int getNetType() {
TelephonyManager  manager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        switch (manager.getNetworkType()) {
            case TelephonyManager.NETWORK_TYPE_GPRS:
            case TelephonyManager.NETWORK_TYPE_CDMA:
            case TelephonyManager.NETWORK_TYPE_GSM:
            case TelephonyManager.NETWORK_TYPE_EDGE:
            case TelephonyManager.NETWORK_TYPE_1xRTT:
            case TelephonyManager.NETWORK_TYPE_IDEN:
                return 2;  // 2G网络
            case TelephonyManager.NETWORK_TYPE_EVDO_A:
            case TelephonyManager.NETWORK_TYPE_UMTS:
            case TelephonyManager.NETWORK_TYPE_EVDO_0:
            case TelephonyManager.NETWORK_TYPE_HSDPA:
            case TelephonyManager.NETWORK_TYPE_HSUPA:
            case TelephonyManager.NETWORK_TYPE_HSPA:
            case TelephonyManager.NETWORK_TYPE_EVDO_B:
            case TelephonyManager.NETWORK_TYPE_EHRPD:
            case TelephonyManager.NETWORK_TYPE_HSPAP:
            case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
                return 3; // 3G网络
            case TelephonyManager.NETWORK_TYPE_LTE:
            case TelephonyManager.NETWORK_TYPE_IWLAN:
                return 4;   // 4G网络
            case TelephonyManager.NETWORK_TYPE_NR:
                return 5;//5G网络
            default:
                return 0;
        }
    }

3,双卡网络判断及处理
https://www.jianshu.com/p/fbaf08eb59d7
4,信号参数获取

private class SimListener extends PhoneStateListener {

        @Override
        public void onDataConnectionStateChanged(int state) {
            super.onDataConnectionStateChanged(state);
        }

        @Override
        public void onSignalStrengthsChanged(SignalStrength signalStrength) {
            super.onSignalStrengthsChanged(signalStrength);
 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            List<CellSignalStrength> strengths = signalStrength.getCellSignalStrengths();
            if (null != strengths && strengths.size() > 0) {
                CellSignalStrength strength = strengths.get(0);
                if (strength instanceof CellSignalStrengthLte) {
                    CellSignalStrengthLte lte = (CellSignalStrengthLte) strength;
                     int  rsrp = lte.getRsrp();
                     int   rsrq = lte.getRsrq();
                     int  sinr = lte.getRssnr();
                 
                } else if (strength instanceof CellSignalStrengthCdma) {
                    CellSignalStrengthCdma wcdma = (CellSignalStrengthCdma) strength;
                     int rscp = wcdma.getDbm();
                     int ecio =wcdma.getCdmaEcio();
                }
            }
        } else {
                try {
                    Integer rsrp = (Integer) signalStrength.getClass().getMethod("getLteRsrp").invoke(signalStrength);
                    Integer rsrq = (Integer) signalStrength.getClass().getMethod("getLteRsrq").invoke(signalStrength);
                    Integer sinr = (Integer) signalStrength.getClass().getMethod("getLteRssnr").invoke(signalStrength);
                    Integer ecio = (Integer) signalStrength.getClass().getMethod("getCdmaEcio").invoke(signalStrength) / 10;
                    Integer rscp =signalStrength.getClass().getMethod("getWcdmaRscp").invoke(signalStrength);
                } catch (Exception e) {
        }
        }

        @Override
        public void onCellInfoChanged(List<CellInfo> cellInfo) {
            super.onCellInfoChanged(cellInfo);
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值