您只能听取,无法主动切换私有域名的选择和设置,而且华为手机无法动态修改监控。代码如下:
val cMgr: ConnectivityManager = getSystemService(CONNECTIVITY_SERVICE) as ConnectivityManager
if (cMgr != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
cMgr.registerNetworkCallback(NetworkRequest.Builder().build(), object : ConnectivityManager.NetworkCallback() {
@SuppressLint("MissingPermission")
override fun onLinkPropertiesChanged(network: Network, linkProperties: LinkProperties) {
super.onLinkPropertiesChanged(network, linkProperties)
println("onLinkPropertiesChanged(Network = $network, LinkProperties = $linkProperties)")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
println(
"LinkProperties.isPrivateDnsActive = " + linkProperties.isPrivateDnsActive()
.toString() + ", server =" + linkProperties.getPrivateDnsServerName()
)
}
}
})
}
}