在获取latitudelongitude时,我每5分钟向服务器发送一次WakeLockWifiLock消息,但收到错误消息

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

代码片段是,
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;
        }

    }
}

没有任何解决办法。请提出任何建议。
提前谢谢你。

最佳答案

不持有时获取wake lock。全部替换为
wifiLock.acquire()

07-27 20:48