Connectivity Change Broadcast receiver not triggering when phone is in sleep mode
<p>I have a network state change <code>Broadcast Receiver</code> setup for my app. I need to receive wifi connect-disconnect events even when phone is in sleep mode. This works when phone is charging and in sleep, but doesn't when its not in sleep.</p>

<p>here is code</p>

<pre><code>public class NetworkConnectionReceiver extends WakefulBroadcastReceiver {
public static final String INTENT_CONNECTIVITY_CHANGE = "android.net.conn.CONNECTIVITY_CHANGE";

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equalsIgnoreCase(INTENT_CONNECTIVITY_CHANGE)) {
        NetworkChangedEvent event = new NetworkChangedEvent();
        NetworkInfo activeNetworkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
        boolean wifiConnected = activeNetworkInfo != null
                &amp;&amp; activeNetworkInfo.isConnected()
                &amp;&amp; activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI;

        if (wifiConnected) {
            // start a service here
        } 
    }
}
}
</code></pre>

<p>here is how its registered in manifest</p>

<pre><code> &lt;receiver
        android:name=".NetworkConnectionReceiver"
        android:enabled="true"
        android:exported="true"&gt;
        &lt;intent-filter&gt;
            &lt;action android:name="android.net.conn.CONNECTIVITY_CHANGE" /&gt;
            &lt;action android:name="android.net.wifi.STATE_CHANGE" /&gt;
        &lt;/intent-filter&gt;
    &lt;/receiver&gt;
</code></pre>

<p>I am aware of doze mode related issue in Marshmallow and above devices but I am not even receiving events in Kitkat devices when phone is in sleep and its not connected to charger.</p>