I am creating an app that has a background service which continuously gets the WiFi RSSI using the getRssi()
method and decides what it should do depending on the value.
The service is running OK, however, when the screen is locked the service stops updating the value of RSSI, instead, it gets stuck with the last value read before locking the screen.
I tried holding a partial WakeLock
but unfortunately it has no effect.
In the OnStartCommand
of the service I added the wake lock as follows :
wifi =(WifiManager)getApplicationContext().getSystemService(WIFI_SERVICE);
PowerManager pm = (PowerManager)getSystemService(POWER_SERVICE);
PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"MyLock");
wakeLock.acquire();
info = wifi.getConnectionInfo();
RSSI = info.getRssi();
System.out.println(RSSI);
I added the Wake Lock permission to the manifest :
<uses-permission android:name="android.permission.WAKE_LOCK" />
Have anyone had a similar problem?
What is the reason behind this?