在上一家公司做了一个用安卓手机扫描周围频点的功能,虽然在安卓 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 = (</