安卓扫描周围基站信息,获取邻小区频段频点

在上一家公司做了一个用安卓手机扫描周围频点的功能,虽然在安卓 9.0 能获取到频段、频点,但是也只限于自己手机 sim 卡对应的邻小区,作用不太大。

不过也是有人做这个,用 root 的手机底层开发,可以切换自身频点,获取到想要的邻小区数据,软件收费,当时手上还有这么个软件,可是忘了叫什么名字了,有兴趣可以自己找找。

下面记录下我的代码:

代码

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Build;
import android.telephony.CellInfo;
import android.telephony.CellInfoGsm;
import android.telephony.CellInfoLte;
import android.telephony.CellInfoWcdma;
import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static android.content.Context.TELEPHONY_SERVICE;

public class LteUtils {
   

    private static TelephonyManager telephonymanager =
            (TelephonyManager) MyApplication.getContext().getSystemService(TELEPHONY_SERVICE);


    public static List<Map<String, Integer>> getLteInfo() {
   
        List<Map<String, Integer>> mapList = new ArrayList<>();
        try {
   
            //权限确认
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
   
                if (MyApplication.getContext().checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
   
                    //直接返回
                    return mapList;
                }
            }

            //获取周围小区信息
            List<CellInfo> allCellinfo = telephonymanager.getAllCellInfo();
            if (allCellinfo != null) {
   
                for (CellInfo cellInfo : allCellinfo) {
   
                    //GSM
                    if (cellInfo instanceof CellInfoGsm) {
   
                        CellInfoGsm cellInfoGsm = (CellInfoGsm) cellInfo;
                        Map<String, Integer> map = new HashMap<>();
                        map.put("Ci", cellInfoGsm.getCellIdentity().getCid());
                        map.put("Rsrp", cellInfoGsm.getCellSignalStrength().getDbm());
                        map.put("AsuLevel", cellInfoGsm.getCellSignalStrength().getAsuLevel());
                        map.put("Lac", cellInfoGsm.getCellIdentity().getLac());
                        map.put("Tac", cellInfoGsm.getCellSignalStrength().getDbm());
                        mapList.add(map);
                    //WCDMA
                    } else if (cellInfo instanceof CellInfoWcdma) {
   
                        CellInfoWcdma cellInfoWcdma = (</
获取安卓双卡的基站频段信息,可以使用以下步骤: 1. 获取手机权限,包括READ_PHONE_STATE和ACCESS_COARSE_LOCATION权限,在AndroidManifest.xml文件中添加如下代码: ``` <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> ``` 2. 在代码中获取手机的TelephonyManager对象和CellInfo对象,然后通过CellInfo对象获取基站频段信息。下面是示例代码: ``` TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); List<CellInfo> cellInfos = telephonyManager.getAllCellInfo(); for (CellInfo cellInfo : cellInfos) { if (cellInfo instanceof CellInfoGsm) { // GSM网络 CellInfoGsm cellInfoGsm = (CellInfoGsm) cellInfo; int arfcn = cellInfoGsm.getCellIdentity().getArfcn(); // 基站频点 int bsic = cellInfoGsm.getCellIdentity().getBsic(); // 基站识别码 Log.d(TAG, "GSM arfcn: " + arfcn + ", bsic: " + bsic); } else if (cellInfo instanceof CellInfoWcdma) { // WCDMA网络 CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) cellInfo; int uarfcn = cellInfoWcdma.getCellIdentity().getUarfcn(); // 基站频点 int psc = cellInfoWcdma.getCellIdentity().getPsc(); // 基站识别码 Log.d(TAG, "WCDMA uarfcn: " + uarfcn + ", psc: " + psc); } else if (cellInfo instanceof CellInfoLte) { // LTE网络 CellInfoLte cellInfoLte = (CellInfoLte) cellInfo; int earfcn = cellInfoLte.getCellIdentity().getEarfcn(); // 基站频点 int pci = cellInfoLte.getCellIdentity().getPci(); // 基站识别码 Log.d(TAG, "LTE earfcn: " + earfcn + ", pci: " + pci); } else if (cellInfo instanceof CellInfoCdma) { // CDMA网络 CellInfoCdma cellInfoCdma = (CellInfoCdma) cellInfo; int sid = cellInfoCdma.getCellIdentity().getSystemId(); // 系统ID int nid = cellInfoCdma.getCellIdentity().getNetworkId(); // 网络ID int bid = cellInfoCdma.getCellIdentity().getBasestationId(); // 基站ID Log.d(TAG, "CDMA sid: " + sid + ", nid: " + nid + ", bid: " + bid); } } ``` 这段代码会遍历所有的CellInfo对象,然后根据网络类型获取基站频段信息。对于GSM网络,可以获取基站频点基站识别码;对于WCDMA网络,可以获取基站频点基站识别码;对于LTE网络,可以获取基站频点基站识别码;对于CDMA网络,可以获取系统ID、网络ID和基站ID。
评论 20
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值