Android telephony_android获取真实时间

Android telephony_android获取真实时间做一波获取手机卡LET的信息操作。看了一波源码写出来的一些东西首先需要的一些权限(危险权限动态获取一下,之前的里面有):<uses-permissionandroid:name=”android.permission.INTERNET”/><uses-permissionandroid:name=”android.permission.ACCESS_WIFI_ST…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

做一波获取手机卡LET的信息操作。看了一波源码写出来的一些东西

首先需要的一些权限(危险权限动态获取一下,之前的里面有):

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

//首先获取手机管理者类

tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

//获取设备编号

tm.getDeviceId();

//SIM卡提供商的ISO国家代码

tm.getSimCountryIso();

//获取SIM卡序列号

tm.getSimSerialNumber();

//获取网络运营商代号(MCC+MNC)

tm.getNetworkOperator();

//获取网络运营商名称

tm.getNetworkOperatorName();

//获取设备当前所在位置

tm.getCellLocation();

//获取cId,lac,psc,基于位置信息获取

CellLocation cellLocation = tm.getCellLocation();
if(cellLocation instanceof GsmCellLocation) {
    GsmCellLocation location = (GsmCellLocation)cellLocation;
    int cid = location.getCid();
    int lac = location.getLac();
    int psc = location.getPsc();
}

//获取手机类型

tm.getPhoneType();

//获取手机号码

tm.getLine1Number();

//获取国际长途区号

tm.getNetworkCountryIso();

//获取连接状态

tm.getDataState();

//获取网络类型(SDK版本29,才有5G,5G代号NR)

tm.getNetworkType();

//获取临近小区信息

之前的tm.getNeighboringCellInfo();这个方法在SDK29版本里删除掉了,所以得用另一种方法获取。

List<CellInfo> allCellInfo = tm.getAllCellInfo();
//集合返回的第一个数据,allCellInfo.get(0)就是当前小区的数据
        String ss = allCellInfo.toString();
        for(CellInfo cellInfo : allCellInfo){
            if(cellInfo instanceof CellInfoGsm) {
                CellInfoGsm infoGsm = (CellInfoGsm) cellInfo;
                CellIdentityGsm cellIdentity = infoGsm.getCellIdentity();
                int cid = cellIdentity.getCid();
                int lac = cellIdentity.getLac();
                int psc = cellIdentity.getPsc();
                int arfcn = cellIdentity.getArfcn();
                int rsrp = infoGsm.getCellSignalStrength().getDbm();
                str = "2G=====cid:"+cid+"=====lac:"+lac+"=====psc:"+psc+"=====arfcn:"+arfcn+"=====rsrp:"+rsrp+"\n";
            }else if(cellInfo instanceof CellInfoWcdma){
                CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) cellInfo;
                int cid = cellInfoWcdma.getCellIdentity().getCid();
                int lac = cellInfoWcdma.getCellIdentity().getLac();
                int psc = cellInfoWcdma.getCellIdentity().getPsc();
                int rsrp = cellInfoWcdma.getCellSignalStrength().getDbm();
                serverCellInfo.asulevel = cellInfoWcdma.getCellSignalStrength().getAsuLevel();
                str = "3G=====cid:"+cid+"=====lac:"+lac+"=====psc:"+psc+"=====rsrp:"+rsrp+"\n";
            }else if(cellInfo instanceof CellInfoLte){
                CellInfoLte cellInfoLte = (CellInfoLte) cellInfo;
                int cid = cellInfoLte.getCellIdentity().getCi();
                int pci = cellInfoLte.getCellIdentity().getPci();
                int tac = cellInfoLte.getCellIdentity().getTac();
                int earfcn = cellInfoLte.getCellIdentity().getEarfcn();
                int rsrp = cellInfoLte.getCellSignalStrength().getRsrp();
                int rsrq = cellInfoLte.getCellSignalStrength().getRsrq();
//                Object rssi = cellInfoLte.getCellSignalStrength().getRssi();
                Object rssnr = cellInfoLte.getCellSignalStrength().getRssnr();
                Object bandwidth = cellInfoLte.getCellIdentity().getBandwidth();
                str = "4G=====cid:"+cid+"=====pci:"+pci+"=====tac:"+tac+"=====earfcn:"+earfcn+"=====rsrp:"+rsrp+"=====rsrq:"
                        +rsrq+"=====rssnr:"+rssnr+"=====bandWidth:"+bandwidth+"\n";

            }else if(cellInfo instanceof CellInfoNr){
                CellInfoNr cellInfoNr = (CellInfoNr) cellInfo;
                int asuLevel = cellInfoNr.getCellSignalStrength().getAsuLevel();
                int rsrp = cellInfoNr.getCellSignalStrength().getDbm();
                int level = cellInfoNr.getCellSignalStrength().getLevel();
                str = "5G=====asuLevel:"+asuLevel+"=====rsrp:"+rsrp+"=====level:"+level;
            }
        }

注:商用手机无法获得5G下的小区信息,可以检测到是NR(5G)网络,但是即使在5G情况下获得的仍是4G锚点小区的信息!!!想要获取需要跟手机厂家去购买获取Root过的手机。

 

//上面那个方法没法获取rssi,总是报错,获取sinr,cqi,rsrp,rssi等信息

//注册一个监听,利用反射拿到这些数据,在监听后拿数据即可

class MyPhoneStateListener extends PhoneStateListener {
    @Override
    public void onSignalStrengthsChanged(SignalStrength signalStrength) {
        super.onSignalStrengthsChanged(signalStrength);
        if (phoneGeneralInfo.ratType == TelephonyManager.NETWORK_TYPE_LTE) {
            try {
                int rssi = (Integer) signalStrength.getClass().getMethod("getLteSignalStrength").invoke(signalStrength);
                int rsrp = (Integer) signalStrength.getClass().getMethod("getLteRsrp").invoke(signalStrength);
                int rsrq = (Integer) signalStrength.getClass().getMethod("getLteRsrq").invoke(signalStrength);
                int sinr = (Integer) signalStrength.getClass().getMethod("getLteRssnr").invoke(signalStrength);
                int cqi = (Integer) signalStrength.getClass().getMethod("getLteCqi").invoke(signalStrength);
            } catch (Exception e) {
                e.printStackTrace();
                return;
            }
        } else if (phoneGeneralInfo.ratType == TelephonyManager.NETWORK_TYPE_GSM) {
            try {
                serverCellInfo.rssi = signalStrength.getGsmSignalStrength();
                serverCellInfo.rsrp = (Integer) signalStrength.getClass().getMethod("getGsmDbm").invoke(signalStrength);
                serverCellInfo.asulevel = (Integer) signalStrength.getClass().getMethod("getAsuLevel").invoke(signalStrength);
            } catch (Exception e) {
                e.printStackTrace();
                return;
            }
        } else if (phoneGeneralInfo.ratType == TelephonyManager.NETWORK_TYPE_TD_SCDMA) {
            try {
                int rssi = (Integer) signalStrength.getClass().getMethod("getTdScdmaLevel").invoke(signalStrength);
                int rsrp = (Integer) signalStrength.getClass().getMethod("getTdScdmaDbm").invoke(signalStrength);
                int asulevel = (Integer) signalStrength.getClass().getMethod("getAsuLevel").invoke(signalStrength);
            } catch (Exception e) {
                e.printStackTrace();
                return;
            }
        }
    }
}

//监听使用方法,需要调用一下

MyPhoneStateListener myPhoneStateListener = new MyPhoneStateListener();
tm.listen(myPhoneStateListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);

 

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

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/185296.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Html背景图片_html背景图片平铺

    Html背景图片_html背景图片平铺这里面有许多简洁的html背景界面,对,重要的是简洁,而且很好看,verynice:https://www.toptal.com/designers/subtlepatterns/可能需要梯子。网站提供一键预览:   …

    2022年10月5日
    0
  • 企业发卡源码+教程[通俗易懂]

    企业发卡源码+教程[通俗易懂]介绍:程序对接了易支付接口,后台增加商铺模板搭建教程:准备服务器《空间主机》+域名+上传源码解压,删除压缩包。修改数据库内容位置:application/database.php然后进入数据库,导入数据库文件,你的域名+admin=后台后台账号:admin后台网盘下载地址:http://kekewl.cc/elCdqYEXaIA图片:…

    2022年7月14日
    30
  • 西门子PLC学习笔记二-(工作记录)

    西门子PLC学习笔记二-(工作记录)

    2021年12月5日
    47
  • SCI论文投稿信(Cover Letter)的写法及模版

    SCI论文投稿信(Cover Letter)的写法及模版一、写法投稿信(CoverLetter)应该简述所投稿件的核心内容、主要发现和意义,拟投期刊,对稿件处理有无特殊要求等(如“nottoreview”list)。另外,请附上主要作者的中文姓名、通讯地址、电话、传真和e-mail地址。此外有的杂志要求推荐几位审稿人及其联系方式。以及谁已经阅读过该文(当然是牛人)。一般来说,杂志通常要求说明你论文研究的意义,以及与这个杂志的相关性,另外还有…

    2022年5月8日
    125
  • cacls.exe「建议收藏」

    cacls.exe「建议收藏」xpsql.cpp:错误5来自CreateProcess(第737行)怎么解决、很简单的解决方法cmd权限问题cacls.exeC:\WINdows\system32\cmd.exe/e/t/gsystem:FC:\DocumentsandSettings\Administrator>cacls.exeC:\WINdows\system32\cmd.exe…

    2025年6月13日
    0
  • NFS原理详解_简述NFS服务的工作流程

    NFS原理详解_简述NFS服务的工作流程【mike:前面大概看了看,后面看不懂】source:http://blog.51cto.com/atong/1343950NFS原理详解原创woshiliwentong2013-12-2312:17评论(4)24682人阅读PS:哈哈,这篇的篇幅真的非常的长。要看完真的要有很强的耐心那。我自己写也快写吐了呢。[ATon

    2022年10月26日
    0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号