是否可以在Android中使用编程打开私有DNS设置?
有没有办法以编程方式设置专用DNS值?
h79rfbju1#
只能监听,不能主动切换私有域名的选择和设置,华为移动的也一直无法动态修改监听,代码如下:
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() ) } } }) } }
1条答案
按热度按时间h79rfbju1#
只能监听,不能主动切换私有域名的选择和设置,华为移动的也一直无法动态修改监听,代码如下: