Exceeded the maximum number of Wi-Fi locks

I send latitudeand longitudeevery 5 minutes to the server at the time of receipt WakeLockand WifiLock, but I get an error

java.lang.UnsupportedOperationException: Exceeded maximum number of wifi locks
at android.net.wifi.WifiManager$WifiLock.acquire(WifiManager.java:1622)

fragment code

public class WakeLocker {
    private WakeLock wl_cpu;
    private PowerManager mPowerManager;
    private WifiLock wifiLock = null;

    @SuppressLint({ "InlinedApi", "Wakelock" })
    public void acquire(Context ctx) {
        mPowerManager = (PowerManager) ctx
                .getSystemService(Context.POWER_SERVICE);

        WifiManager wm = (WifiManager) ctx
                .getSystemService(Context.WIFI_SERVICE);
        wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF,
                "MyWifiLock");
        wifiLock.acquire();

        wl_cpu = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
                | PowerManager.ACQUIRE_CAUSES_WAKEUP
                | PowerManager.ON_AFTER_RELEASE, "MyCpuLock");
        wl_cpu.acquire(10000);
    }

    public void release() {

        if ((wifiLock != null) || (wifiLock.isHeld() == true)) {
            wifiLock.release();
            wifiLock = null;
        }
        if ((wl_cpu != null) || (wl_cpu.isHeld() == true)) {
            wl_cpu.release();
            wl_cpu = null;
        }

    }
}

It doesn’t work out any solution. Please any suggestion. Thank you in advance.

+3
source share
2 answers

I'm just surrounded by a cork.

0
source

Acquire wake lockwhen it is not held. Replace everything wifiLock.acquire()with if (!wifiLock.held()) wifiLock.acquire()

0
source

All Articles