微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法在 android API 28和其他东西中获取移动网络的子类型

如何解决无法在 android API 28和其他东西中获取移动网络的子类型

所以我试图获取我的 android 应用程序的所有参数,这个应用程序必须获取一系列与我相关的数据,例如 MCC、MNC、LAC、CID、RSRP、类型或网络、网络的子类型和基站。同样在我的代码中,我实现了一个 SubscriptionInfo 列表(我不知道是否有必要)。从我所有的代码中,我不知道如何获得 MCC、MNC、子类型和 eNB 计算的值。在某些情况下,LAC 将 CID 作为价值,我不明白,如果你能澄清这会很棒。我是一名学生,我刚刚开始学习android。关于我需要的权限,一切都经过了很好的检查。为了进行测试,我使用了具有 API 28 的手机,但无法设置模拟器。

private void showinfo() {
    try {

        LocationManager lm = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,(LocationListener) this);
        if(lm!=null){
            Log.i(LOG_TAG,"LOCATION MANAGER");
        }

        TelephonyManager manager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
        if(manager!=null){
            Log.i(LOG_TAG,"TELEPHONY MANAGER");
        }

        Location location = lm.getLastKNownLocation(LocationManager.GPS_PROVIDER);
        if(location!=null){
            Log.i(LOG_TAG,"LOCATION");
        }

        String networkOperator = manager.getNetworkOperator();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {

            SubscriptionManager subsManagerPh = (SubscriptionManager) this.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);

            List<SubscriptionInfo> subsListPh = subsManagerPh.getActiveSubscriptionInfoList();

            
            if (subsListPh != null && location != null) {
                Log.i(LOG_TAG,"SUBSLIST");

                for (SubscriptionInfo subsInfoPh : subsListPh) {
                    
                    if (subsInfoPh != null) {

                        longit = location.getLongitude();
                        latit= location.getLatitude();
                        altit = location.getAltitude();


                        if (!TextUtils.isEmpty(networkOperator)) {
                             valueMcc = Integer.parseInt(networkOperator.substring(0,3));
                             valueMnc = Integer.parseInt(networkOperator.substring(3));
                        }
                        else{
                            mcc = manager.getNetworkCountryIso();
                            mcc = manager.getSimCountryIso();
                        }

                     
                        if (manager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
                           
                            List <CellInfo> infoCell = manager.getAllCellInfo();

                                for (CellInfo cellInfo : infoCell)
                                {
                                    if (cellInfo instanceof CellInfoLte)
                                    {

                                        locAreaCode=((CellInfoLte)cellInfo).getCellIdentity().getTac();
                                        cellId =((CellInfoLte)cellInfo).getCellIdentity().getCi();
                                        ENB = ((CellInfoLte)cellInfo).getCellIdentity().getCi() & 0xffff;
                                        valueRSRP=((CellInfoLte)cellInfo).getCellSignalStrength().getDbm();
                                    }
                                }

                        }
                       
                        latitude = String.valueOf(latit);
                        longitude = String.valueOf(longit);
                        altitude = String.valueOf(altit);
                        lac = String.valueOf(locAreaCode);
                        cid = String.valueOf(cellId);
                        rsrp= String.valueOf(valueRSRP);
                        enb = String.valueOf(ENB);
                        infoNetwork = manager.getDatanetworkType();
                       
                        switch (infoNetwork) {
                            case 7: type= "1xRTT"; //TelephonyManager.NETWORK_TYPE_1xRTT
                            case 4: type= "CDMA"; //TelephonyManager.NETWORK_TYPE_CDMA
                            case 2: type= "EDGE"; //TelephonyManager.NETWORK_TYPE_EDGE
                            case 14: type= "eHRPD"; //TelephonyManager.NETWORK_TYPE_EHRPD
                            case 5: type= "EVDO rev. 0"; //TelephonyManager.NETWORK_TYPE_EVDO_0
                            case 6: type= "EVDO rev. A"; //TelephonyManager.NETWORK_TYPE_EVDO_A
                            case 12: type= "EVDO rev. B"; //TelephonyManager.NETWORK_TYPE_EVDO_B
                            case 1: type= "GPRS"; //TelephonyManager.NETWORK_TYPE_GPRS
                            case 8: type= "HSDPA"; //TelephonyManager.NETWORK_TYPE_HSDPA
                            case 10: type= "HSPA"; //TelephonyManager.NETWORK_TYPE_HSPA
                            case 15: type= "HSPA+"; //TelephonyManager.NETWORK_TYPE_HSPAP
                            case 9: type= "HSUPA"; //TelephonyManager.NETWORK_TYPE_HSUPA
                            case 11: type= "iDen"; //TelephonyManager.NETWORK_TYPE_IDEN
                            case 13: type= "LTE"; //TelephonyManager.NETWORK_TYPE_LTE
                            case 3: type= "umts"; //TelephonyManager.NETWORK_TYPE_umts
                            case 0:
                                if(infoNetwork == 13){
                                    type= "LTE";
                                }
                                else {
                                    type = "UnkNown";
                                }

                        }

                    }
                }
            }
        } else { 

            longit = location.getLongitude();
            latit= location.getLatitude();
            altit = location.getAltitude();

            if (!TextUtils.isEmpty(networkOperator)) {
                valueMcc = Integer.parseInt(networkOperator.substring(0,3));
                valueMnc = Integer.parseInt(networkOperator.substring(3));
            }
            else{
                mcc = manager.getNetworkCountryIso();
                mcc = manager.getSimCountryIso();
            }

          

            if (manager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
               
                List <CellInfo> infoCell = manager.getAllCellInfo();
                
                    for (CellInfo cellInfo : infoCell)
                    {
                        if (cellInfo instanceof CellInfoLte)
                        {
                           
                            locAreaCode=((CellInfoLte)cellInfo).getCellIdentity().getTac();
                            cellId =((CellInfoLte)cellInfo).getCellIdentity().getCi();
                            ENB = ((CellInfoLte)cellInfo).getCellIdentity().getCi() & 0xffff;
                            valueRSRP=((CellInfoLte)cellInfo).getCellSignalStrength().getDbm();
                        }
                    }

            }
            latitude = String.valueOf(latit);
            longitude = String.valueOf(longit);
            altitude = String.valueOf(altit);
            lac = String.valueOf(locAreaCode);
            cid = String.valueOf(cellId);
            rsrp= String.valueOf(valueRSRP);
            enb = String.valueOf(ENB);
            mcc = String.valueOf(valueMcc);
            mnc = String.valueOf(valueMnc);
            infoNetwork = manager.getDatanetworkType();
            switch (infoNetwork) {
                case 7: type= "1xRTT"; //TelephonyManager.NETWORK_TYPE_1xRTT
                case 4: type= "CDMA"; //TelephonyManager.NETWORK_TYPE_CDMA
                case 2: type= "EDGE"; //TelephonyManager.NETWORK_TYPE_EDGE
                case 14: type= "eHRPD"; //TelephonyManager.NETWORK_TYPE_EHRPD
                case 5: type= "EVDO rev. 0"; //TelephonyManager.NETWORK_TYPE_EVDO_0
                case 6: type= "EVDO rev. A"; //TelephonyManager.NETWORK_TYPE_EVDO_A
                case 12: type= "EVDO rev. B"; //TelephonyManager.NETWORK_TYPE_EVDO_B
                case 1: type= "GPRS"; //TelephonyManager.NETWORK_TYPE_GPRS
                case 8: type= "HSDPA"; //TelephonyManager.NETWORK_TYPE_HSDPA
                case 10: type= "HSPA"; //TelephonyManager.NETWORK_TYPE_HSPA
                case 15: type= "HSPA+"; //TelephonyManager.NETWORK_TYPE_HSPAP
                case 9: type= "HSUPA"; //TelephonyManager.NETWORK_TYPE_HSUPA
                case 11: type= "iDen"; //TelephonyManager.NETWORK_TYPE_IDEN
                case 13: type= "LTE"; //TelephonyManager.NETWORK_TYPE_LTE
                case 3: type= "umts"; //TelephonyManager.NETWORK_TYPE_umts
                case 0:
                    if(infoNetwork == 13){
                    type= "LTE";
                }
                else {
                    type = "UnkNown";
                } 
            }
        }
        Log.i(LOG_TAG,"Latitude : " + latitude);
        Log.i(LOG_TAG,"Longitude : " + longitude);
        Log.i(LOG_TAG,"Altitude : " + altitude);
        Log.i(LOG_TAG,"MCC : " + mcc);
        Log.i(LOG_TAG,"MNC : " + mnc);
        Log.i(LOG_TAG,"LAC : " + lac);
        Log.i(LOG_TAG,"CID : " + cid);
        Log.i(LOG_TAG,"RSRP : " + rsrp);
        Log.i(LOG_TAG,"Type : " + type);
        Log.i(LOG_TAG,"eNB : " + enb);

        this.showLatitude.setText(latitude);

        this.showLongitude.setText(longitude);

        this.showAltitude.setText(altitude);

        this.showMCC.setText(mcc);

        this.showMNC.setText(mnc);

        this.showLAC.setText(lac);

        this.showCID.setText(cid);

        this.showRSRP.setText(rsrp);

        this.showType.setText(type);

        this.showENB.setText(enb);

    } catch (Exception ex) {
        Log.e(LOG_TAG,"Error: ",ex);
        Toast.makeText(this,"Error: " + ex.getMessage(),Toast.LENGTH_LONG).show();
        ex.printstacktrace();
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。