Monitor WiFi sleep mode events

262 views Asked by At

I have to monitor the connectivity of the device automatically, to do that I have my receiver registered with

<receiver android:name=".NetworkStateReceiver" android:exported="true">
        <intent-filter>
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
            <action android:name="android.net.wifi.STATE_CHANGE"/>
            <action android:name="android.net.wifi.supplicant.CONNECTION_CHANGE" />
        </intent-filter>
</receiver>

It works fine, but when the WiFi goes to sleep mode, the network info will have the state DISCONNECTED/BLOCKED. This is ok, I understand why it does this to save battery etc.

The issue is that the receiver doesn't receive an intent when the WiFi goes to sleep mode. Same thing if I wake up the device, the WiFi will switch to connected state but I won't receive an intent.

(Tested on a Nexus 5X)

Any way I could receive those events without having to use an alarm that would fire every X minutes to check the state?

Checked Connectivity Change Broadcast receiver not triggering when phone is in sleep mode but answer seems irrelevant

0

There are 0 answers