华为 nova 6(5g)如何判断当前是4G还是5G网络?

机器配置:

  • 华为 nova 6(5g)
  • EMUI 10.0.1
  • Android 10
  • 网络运营商是移动

要实现的功能:

  • 在开启5G的情况下,判断当前手机连接的蜂窝网络是4G还是5G。

尝试过的办法:

  • 利用 TelephonyManager.getNetworkType() 函数,其返回值是一直是0。
  • 利用 TelephonyManager.getDataNetworkType() 函数,返回值一直是NETWORK_TYPE_UNKNOWN。
  • 利用 ConnectivityManager.getActiveNetworkInfo().getSubtype() 函数,这个可以识别 4G 网络,但是连接到 5G 网络时(手机界面显示是5G,测速为数百M)仍然返回是 4G 网络。
  • 利用 TelephonyManager.getAllCellInfo() 函数,检查其返回的 List<CellInfo> 中是否同时存在 CellInfoLte 和 CellInfoNr,并且二者状态都是 registered(即对其调用 isRegistered() 返回 true)。结果在连接到5G时,其返回 List 中不存在 CellInfoNr 类型的对象。

请问是否是做法有误?有何可行的方法?

阅读 10.5k
1 个回答
推荐问题