title: Broadcast receiver not working background on some devices
body: <p>I am trying to get WiFi connection changing event using Broadcast Receiver class. I have tested this on Samsung S7 edge and HTC 626Q and it works well (even when the app is closed), but this is not working on Huawei GR5 2017 if the app is closed. It works only when the app is running on screen. Both S7 and GR5 devices have Android 7 (Nougat) OS.</p>
  
  <p><strong>Broadcast Receiver</strong></p>
  
  <pre><code>public class NetworkChangeReceiver extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context context, Intent intent) {
          Toast.makeText(context,intent.getAction(),Toast.LENGTH_SHORT).show();
      }
  }
  </code></pre>
  
  <p><strong>AndroidManifest file</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="chanakamadurangakarunarathne.testbroadcastevents"&gt;
  
      &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:roundIcon="@mipmap/ic_launcher_round"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;
          &lt;activity android:name=".MainActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
          &lt;receiver
              android:name=".NetworkChangeReceiver"
              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;action android:name="android.net.nsd.STATE_CHANGED" /&gt;
                  &lt;action android:name="android.net.wifi.NETWORK_IDS_CHANGED" /&gt;
                  &lt;action android:name="android.net.wifi.STATE_CHANGE" /&gt;
                  &lt;action android:name="android.net.wifi.WIFI_STATE_CHANGED" /&gt;
                  &lt;action android:name="android.net.wifi.p2p.CONNECTION_STATE_CHANGE" /&gt;
                  &lt;action android:name="android.net.wifi.p2p.DISCOVERY_STATE_CHANGE" /&gt;
                  &lt;action android:name="android.net.wifi.p2p.PEERS_CHANGED" /&gt;
                  &lt;action android:name="android.net.wifi.p2p.STATE_CHANGED" /&gt;
                  &lt;action android:name="android.net.wifi.p2p.THIS_DEVICE_CHANGED" /&gt;
                  &lt;action android:name="android.net.wifi.supplicant.CONNECTION_CHANGE" /&gt;
                  &lt;action android:name="android.net.wifi.supplicant.STATE_CHANGE" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>I know I can use Services, but It would be nice if I can use Broadcast Receiver for all devices.
  I found a lot of questions about "Broadcast Receiver not working background" but I couldn't find an answer for my question.
  Why this happens and is there a way to overcome this (Using Broadcast Receiver only)?</p>