如何查询HarmonyOS中的移动网络信号强度参数 & 邻小区参数?

如何获取当前移动网络的

  1. 服务小区的参数(比如NR-TAC, NR-PCI, NR-CI),
  2. 邻小区的相关参数(BAND, NR ARFCN)。
  3. 以及当前网络的信号强度(SS RSRP, SS RSRQ, SS SINR)。

在文档中,我查询到组件 @ohos.telephony.radio (网络搜索) 可以获取一些相关信息。
但根据当前文档所提供的,能够获到的参数不全。

请问,当前harmonyOS有开放这个查询接口吗。有的话,我可以到哪里获得相关参考呢?
谢谢。

尝试查阅文档。希望获得指导答复。

阅读 976
1 个回答

通过connection模块能力判断当前网络连接状态,获取连接网络类型、网卡地址、代理信息等信息

export default class connModle {
  isConn: boolean = false;//是否连接网络
  netCapList: Array<connection.NetCap> | undefined = [];//网络状态
 
  netBearType: connection.NetBearType = -1;//网络类型
  netLinks : connection.LinkAddress = {} as connection.LinkAddress; //链路地址(ip)
  netRotues : connection.RouteInfo = {} as connection.RouteInfo;   //路由信息
  netGateway : connection.NetAddress = {} as connection.NetAddress; //网关信息
  netInterfaceName : string = "testName";          //网卡名称
  netProxy : connection.HttpProxy = {} as connection.HttpProxy;    //网络代理
 
  linkUp : number|undefined = 0;      //上行带宽
  linkDown : number|undefined = 0;    //下行带宽
 
  radioData: radio.NetworkState = {} as radio.NetworkState;//蜂窝网
  radioNetType: radio.NetworkType = {} as radio.NetworkType;//蜂窝网类型
 
  //网络是否有网判断
  async isConnTest() {
    //获取当前默认网络
    connection.getDefaultNet().then((netHandle: connection.NetHandle) => {
      //获取对应的网络的能力信息
      connection.getNetCapabilities(netHandle).then((data: connection.NetCapabilities) => {
 
        console.info("net1 Capabilities : " + JSON.stringify(data));
        //网络带宽
        this.linkUp = data.linkUpBandwidthKbps;
        this.linkDown = data.linkDownBandwidthKbps;
        //网络类型
        this.netBearType = data.bearerTypes[0];
        //网络能力判断 (12具备网络能力 16网络能力通过验证)
        this.netCapList = data.networkCap;
        if(this.netCapList != undefined){
          if(this.netCapList[0]==12 && this.netCapList[1]==16){
            this.isConn = true;
            console.info("net1 isConn :"+ JSON.stringify(this.isConn))
            console.info("net1 当前网络具备连接能力");
          }
 
        }
      })
 
      // //默认网络能力
      // connection.getConnectionProperties(netHandle).then((data: connection.ConnectionProperties) => {
      //   console.info("net1 connection properties : " + JSON.stringify(data));
      // })
    })
  }
 
  //蜂窝网络制式
  getNetType(slotId: number) {
    //获取网络运营商
    radio.getNetworkState((err: BusinessError, data: radio.NetworkState) => {
      if (err) {
        console.info(`net1 getNetworkState failed, callback: err->${JSON.stringify(err)}`);
        return;
      }
      this.radioData = data;
      console.info(`net1 getNetworkState success, callback: data->${JSON.stringify(data)}`);
    });
 
    //获取蜂窝网络类型
    //GSM:2G CDMA:电信2G WCDMA:3G TDSCDMA:3G LTE:4G NR:5G
    radio.getSignalInformation(slotId, (err: BusinessError, data: Array<radio.SignalInformation>) => {
      if (err) {
        console.info(`net1 getSignalInformation failed, callback: err->${JSON.stringify(err)}`);
        return;
      }
      this.radioNetType = data[0].signalType;
      console.info(`net1 getSignalInformation success, callback: data->${JSON.stringify(data)}`);
    });
  }
 
  //网络信息获取
  getNetProperties() {
    //获取当前默认网络
    connection.getDefaultNet().then((netHandle: connection.NetHandle) => {  //wifi 移动网络
      //默认网络能力
      connection.getConnectionProperties(netHandle).then((data: connection.ConnectionProperties) => {
        this.netInterfaceName = data.interfaceName;
        this.netLinks = data.linkAddresses[0];
        this.netRotues = data.routes[0];  //ip
        this.netGateway = data.dnses[0];
 
        console.info("net1 netLinks : " + JSON.stringify(this.netLinks));
        console.info("net1 netRotues : " + JSON.stringify(this.netRotues));
        console.info("net1 netGateway : " + JSON.stringify(this.netGateway));
 
      })
    })
  }
 
  //网络代理获取
  getProxy(){
    connection.getDefaultHttpProxy((error: BusinessError, data: connection.HttpProxy) => {
      if(error) {
        console.info("net1 error : " + JSON.stringify(error));
        return
      }
      console.info("net1 httpProxy : " + JSON.stringify(data));
        this.netProxy = data;
    });
  }
}

没有找到信号强度对应api

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题