在上一家公司做了一个用安卓手机扫描周围频点的功能,虽然在安卓 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) {//GSMif (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 = (CellInfoWcdma) cellInfo;Map<String, Integer> map = new HashMap<>();map.put("Ci", cellInfoWcdma.getCellIdentity().getCid());map.put("Rsrp", cellInfoWcdma.getCellSignalStrength().getDbm());map.put("Psc", cellInfoWcdma.getCellIdentity().getPsc());map.put("AsuLevel", cellInfoWcdma.getCellSignalStrength().getAsuLevel());map.put("Lac", cellInfoWcdma.getCellIdentity().getLac());mapList.add(map);//Lte} else if (cellInfo instanceof CellInfoLte) {CellInfoLte cellInfoLte = (CellInfoLte) cellInfo;Map<String, Integer> map = new HashMap<>();map.put("Ci", cellInfoLte.getCellIdentity().getCi());map.put("Tac", cellInfoLte.getCellIdentity().getTac());map.put("Rsrp", cellInfoLte.getCellSignalStrength().getDbm());map.put("Pci", cellInfoLte.getCellIdentity().getPci());//在7.0以上才能获取频点if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {map.put("Earfcn", cellInfoLte.getCellIdentity().getEarfcn());} else {map.put("Earfcn", 0);}//9.0才能过去频段if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {map.put("Bandwidth", cellInfoLte.getCellIdentity().getBandwidth());}map.put("Mcc", cellInfoLte.getCellIdentity().getMcc());map.put("Mnc", cellInfoLte.getCellIdentity().getMnc());mapList.add(map);} else {//旧设备mapList.addAll(getServerCellInfoOnOlderDevices());}}}} catch (Exception e) {//旧设备mapList.addAll(getServerCellInfoOnOlderDevices());}return mapList;}/*** 旧设备(低安卓版本)获取相关信息*/private static List<Map<String, Integer>> getServerCellInfoOnOlderDevices() {List<Map<String, Integer>> mapList = new ArrayList<>();if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {if (MyApplication.getContext().checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED&& MyApplication.getContext().checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {//直接返回return mapList;}}GsmCellLocation location = (GsmCellLocation) telephonymanager.getCellLocation();Map<String, Integer> map = new HashMap<>();map.put("Ci", location.getCid());map.put("Tac", location.getLac());map.put("Psc", location.getPsc());mapList.add(map);return mapList;}/*** 将获取到的数据转成 SweepInfo* @param mapList 数据* @return SweepInfo list*/public static List<SweepInfo> LteMapToInfo(List<Map<String, Integer>> mapList) {List<SweepInfo> datas = new ArrayList<>();int index = 0;for (Map<String, Integer> map : mapList) {SweepInfo info = new SweepInfo();info.setOrder(index);info.setBand(Utils.getBandFromRate("" + map.get("Earfcn")));info.setOprater(Utils.getOpretorFromRate("" + map.get("Earfcn")));info.setCi("" + map.get("Ci"));info.setPci("" + map.get("Pci"));info.setRsrp("" + map.get("Rsrp"));info.setEarfcn("" + map.get("Earfcn"));index++;datas.add(info);}return datas;}
}

MyApplication 是自己定义的 Application,自己写一下吧,就是获取个 context。

  • SweepInfo
public class SweepInfo implements Parcelable, Comparable<SweepInfo> {private int order;private String band;private String earfcn;private String oprater;private String pci;private String priority;private String rsrp;private String tac;private String ci;private String rsrq;private String bw;public String getPci() {return pci;}public void setPci(String pci) {this.pci = pci;}public String getCi() {return ci;}public void setCi(String ci) {this.ci = ci;}public int getOrder() {return order;}public void setOrder(int order) {this.order = order;}public String getOprater() {return oprater;}public void setOprater(String oprater) {this.oprater = oprater;}public String getBand() {return band;}public void setBand(String band) {this.band = band;}public String getEarfcn() {return earfcn;}public void setEarfcn(String earfcn) {this.earfcn = earfcn;}public String getRsrp() {return rsrp;}public void setRsrp(String rsrp) {this.rsrp = rsrp;}public String getPriority() {return priority;}public void setPriority(String priority) {this.priority = priority;}public String getTac() {return tac;}public void setTac(String tac) {this.tac = tac;}public String getRsrq() {return rsrq;}public void setRsrq(String rsrq) {this.rsrq = rsrq;}public String getBw() {return bw;}public void setBw(String bw) {this.bw = bw;}public static final Creator<SweepInfo> CREATOR = new Creator<SweepInfo>() {public SweepInfo createFromParcel(Parcel source) {SweepInfo info = new SweepInfo();info.setOrder(source.readInt());info.setBand(source.readString());info.setEarfcn(source.readString());info.setOprater(source.readString());info.setPci(source.readString());info.setPriority(source.readString());info.setRsrp(source.readString());info.setTac(source.readString());info.setCi(source.readString());info.setRsrq(source.readString());info.setBw(source.readString());return info;}public SweepInfo[] newArray(int size) {return new SweepInfo[size];}};@Overridepublic int describeContents() {return 0;}@Overridepublic void writeToParcel(Parcel parcel, int i) {parcel.writeInt(order);parcel.writeString(band);parcel.writeString(earfcn);parcel.writeString(oprater);parcel.writeString(pci);parcel.writeString(priority);parcel.writeString(rsrp);parcel.writeString(tac);parcel.writeString(ci);parcel.writeString(rsrq);parcel.writeString(bw);}@Overridepublic int compareTo(@NonNull SweepInfo sweepInfo) {return - Integer.parseInt(this.rsrp) + Integer.parseInt(sweepInfo.getRsrp());}}

这就是个数据类,用来存放扫描到的频点信息。

使用

//申请权限
requestRunTimePermission(new String[]{Manifest.permission.READ_PHONE_STATE,Manifest.permission.ACCESS_COARSE_LOCATION}, new BaseActivity.PermissionListener() {@Overridepublic void onGranted() {//较为耗时,移到进程中处理new Thread(() -> {try{ArrayList<SweepInfo> infoTemp = new ArrayList<>(LteUtils.LteMapToInfo(LteUtils.getLteInfo()));//do u want in UI threadrunOnUiThread(new Runnable() {@Overridepublic void run() {}});}catch (Exception e){e.printStackTrace();}}).start();}@Overridepublic void onGranted(List<String> grantedPermission) {}@Overridepublic void onDenied(List<String> deniedPermission) {}
});

这里需要确认下权限,记得在 manifest 里面加上,这个申请权限的方法是我封装的,读者自己申请下,很简单的。

相关名词介绍

  • MCC,Mobile Country Code,移动国家代码(中国的为460);

  • MNC,Mobile Network Code,移动网络号码(中国移动为0,中国联通为1,中国电信为2);

  • LAC,Location Area Code,位置区域码;

  • CID,Cell Identity,基站编号;

  • BSSS,Base station signal strength,基站信号强度。

  • eNB E-UTRAN Node B 为LTE系统中E-UTRAN的组成部分,计算eNB的方式是 ci = eNB*256+cid

结语

这里虽然能获取到一些频段、频点信息,可是限制性还剩挺大的,上面代码也很简陋。这里也推荐一个软件,里面有获取 LTE、WiFi、Gps 相关信息的功能,虽然有广告,还是不错的,名字叫 cellular - Z,可以自己去下载。

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

  1. 高德地图通过基站信息获取经纬度和具体位置

    背景 有个手表项目,手表传给服务器不是经纬度而是基站信息,现在通过基站信息获取当前位置 准备 去高德地图申请个key 代码 请求接口 http://apilocate.amap.com/positio ...

  2. android获取到电信的手机号码,Android基站信息获取以及Sim卡相关信息获取

    概述: 本篇主要介绍Android获取基站信息的方式,除此之外,还有SIM卡相关字段获取,先介绍一些缩写的概念,后续更新代码的写法. 前言:之前有碰到一个需求,需要获取SIM卡的相关属性:IMSI号. ...

  3. 上海域格ASR平台CAT1模块MQTT和基站信息功能

    上海域格ASR平台CAT1模块MQTT和基站信息获取功能 MQTT透传相关指令和说明 AT+IMQTTADDR=222.66.94.47,1883,client_id0     //设置域名端口 cl ...

  4. iPhone/iOS获得基站信息

    解决完了Android,下面应该就到了iPhone了.这个问题网上搜索的时候基本都是一个代码版本. 参考 iphone-wireless. 当然,我们实际上有三种方法可以获取,目前我并未在真机上面测试 ...

  5. 安卓扫描银行卡获取卡号信息

    不得不说card.io开源的银行卡扫描的三方库真的是很好用啊,非常稀饭,使用简单,而且给你提供的API很多,满足大部分的需要(反正是满足我的各种需求了) 首先上一个效果图 1 对准银行卡的四角就能够扫 ...

  6. Windows Mobile 获取基站信息(LAC,CellID)

    前言: 在做手机定位应用软件,有两种方法可以实行定位: 1.利用基站定位,通过手机获取基站信息,再根据该信息获取经纬度: 2.利用GPS定位,直接获取经纬度信息. 利弊: 1.基站定位精确度低,误差范 ...

  7. Android基站定位——通过手机信号获取基站信息

    基站定位原理:通过手机信号获取基站信息,然后调用第三方公开的根据基站信息查找基站的经纬度值,想要具体地址信息的再根据经纬度值获取具体的地址信息. 一.通过手机信号获取基站信息 通过TelephonyM ...

  8. Android基站定位——通过手机信号获取基站信息(一)

    转载请标明出处:http://blog.csdn.net/android_ls/article/details/8672442 基站定位原理:通过手机信号获取基站信息,然后调用第三方公开的根据基站信息 ...

  9. GPS实时定位、获取基站信息

    好久没有来更新我的博客了 , 最近刚做了一个GPS实时定位和获取基站信息的一个小的Demo ,这个辛酸泪啊- 来给大家们来分享一下 ! 做这个项目我用的是用的原始的手机GPS定位, 因为这个有可能需要 ...

  10. python自动化扫描,多线程枚举获取wifi信息,让你走在任何一个地方都能上网

    python自动化扫描,多线程枚举获取wifi信息,让你走在任何一个地方都能上网. 无线网络在无线局域网的范畴是指"无线相容性认证",实质上是一种商业认证,同时也是一种无线联网技术 ...

最新文章

  1. php agi api,PHP agi 编写测试
  2. oracle 转化为整数,字符串转换成整数——从源码学习
  3. zabbix 安装时常见问题处理
  4. android记录登录状态
  5. Geoserver中切割离线瓦片TileLayer选项中没有900913选项(图层和图层组怎样配置TileLayers的切割选项)
  6. 5.深度学习练习:Deep Neural Network for Image Classification: Application
  7. redis java 缓存服务器_java中对Redis的缓存进行操作
  8. 【Spring】No suitable HttpMessageConverter repsonse type
  9. stm32内部低速rtc_STM32时钟RCC详解
  10. 轮子|Python2异常链
  11. mysql用户创建、授权
  12. ppt 2016 html,2016第1章HTML5.ppt
  13. [转]用户空间和内核空间,进程上下文和中断上下文
  14. HDU - 2087 剪花布条(kmp)
  15. fcntl实现对文件加锁功能
  16. c语言基础--ASCII码表
  17. app上架因为副标题被App Store残忍拒绝!
  18. iMazing 2.11.6 WinMac 中文版 — iOS设备管理工具
  19. Hung-Yi Lee homework[7]: Network Compression
  20. Android QQ 登录接入详细介绍

热门文章

  1. 抓linux肉鸡漏洞,利用MS08067远程溢出漏洞抓肉鸡(3)
  2. 2000~2022年Java学习笔记
  3. 教你用好手中的McAfee 杀毒软件和McAfee 企业集中管理工具EPO
  4. win10下使用mklink命令给C盘软件搬家
  5. Processing自画像
  6. Hadoop YARN(入门) —— Hadoop权威指南5
  7. 淘宝装修基础版全屏店招
  8. C语言的体系结构--main函数存在的必然性(听杨力祥老师的课)
  9. SDP的fmtp部分
  10. restorator打开后win10不能打开任何程序,右键桌面没有打开选项