我知道Android Q中已经添加了5G API,我想知道我们是否可以检测到网络是NSA网络还是SA网络。感谢任何人提供的信息。
问问题
720 次
2 回答
1
根据google文档,我想判断当前网络是NSA还是SA。但我发现 cellConnectionStatus 始终为 0...我使用的是 Galaxy 10s 5G 和 LG v50 5G 设备。
val hasPrimaryLteCell = telephonyManager.allCellInfo
.filterIsInstance(CellInfoLte::class.java)
.any {
it.cellConnectionStatus == CellInfo.CONNECTION_PRIMARY_SERVING
}
val hasSecondaryNrCell = telephonyManager.allCellInfo
.filterIsInstance(CellInfoNr::class.java)
.any {
it.cellConnectionStatus == CellInfo.CONNECTION_SECONDARY_SERVING
}
val isIn5GNonStandaloneMode = hasPrimaryLteCell && hasSecondaryNrCell
于 2019-11-27T08:24:29.747 回答
1
我用以下课程做到这一点:
public class CustomPhoneStateListener extends PhoneStateListener {
Context context;
CustomPhoneStateListener(Context c) {
this.context = c;
}
@Override
public void onDisplayInfoChanged(@NonNull TelephonyDisplayInfo telephonyDisplayInfo) {
if (ActivityCompat.checkSelfPermission(context, android.Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
} else {
super.onDisplayInfoChanged(telephonyDisplayInfo);
if (telephonyDisplayInfo.getOverrideNetworkType() == TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA) {
Log.w(TAG,"5G_NSA");
}
if (telephonyDisplayInfo.getOverrideNetworkType() == TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE) {
Log.w(TAG, "5G_NSA_MMWAVE");
}
}
}
}
然后用这个调用那个类:
telephonyManager.listen(new CustomPhoneStateListener(c),PhoneStateListener.LISTEN_DISPLAY_INFO_CHANGED);
于 2021-02-21T20:22:13.243 回答