我知道Android Q中添加了5G API,我想知道我们是否可以检测到网络是NSA网络还是SA网络。感谢任何人提供的信息。
发布于 2019-11-27 16:24:30
根据google document的说法,我想判断当前的网络是美国国家安全局还是国家安全局。但是我发现cellConnectionStatus总是0..。我使用的是Galaxy10s 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发布于 2021-02-22 04:22:13
我用下面的类来完成这个任务:
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);https://stackoverflow.com/questions/56643059
复制相似问题