ConnectivityManager.NetworkCallback callback = new ConnectivityManager.NetworkCallback() {
public void onAvailable(Network network) {
super.onAvailable(network);
// The Wi-Fi network has been acquired. Bind it to use this network by default.
connectivityManager.bindProcessToNetwork(network);
}
public void onLost(Network network) {
super.onLost(network);
// Called when a network disconnects or otherwise no longer satisfies this request or callback.
}
};
connectivityManager.requestNetwork(
new NetworkRequest.Builder().addTransportType(NetworkCapabilities.TRANSPORT_WIFI).build(),
callback
);
1条答案
按热度按时间ccrfmcuu1#
在Wear OS中,WiFi将自动关闭。如果您希望保持WiFi打开,则应发出NetworkRequest以打开WiFi。