The problem:
I have a Huawei Watch with Android Wear 2.0 . My app should send data over WiFi, but the watch disconnects from the Wifi very fast. How can I keep the watch connected to the Wifi?
Manifest:
In the activity:
public static void keepWiFiOn(Context context, boolean on) {
if (wifiLock == null) {
WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
if (wm != null) {
wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL, TAG);
wifiLock.setReferenceCounted(true);
}
}
if (wifiLock != null) { // May be null if wm is null
if (on) {
wifiLock.acquire();
Log.d(TAG, "Acquired WiFi lock");
} else if (wifiLock.isHeld()) {
wifiLock.release();
Log.d(TAG, "Released WiFi lock");
}
}
}
The WiFi lock is acquired, but the data is sends isn't received on the other side nevertheless.