title: ConnectivityManager getActiveNetworkInfo null pointer exception
body: <p>I see occasionally null pointer exception in connectivity manager. From intent service I check network state by isOnWIFI(this). Exception occurs at line cm.getActiveNetworkInfo(). It's strange because I check for null before I call this.
  Note: Permissions are set.</p>
  
  <pre><code>public static boolean isOnWIFI(Context context) {
      ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
  
          return cm != null
                  //here occurs NullPointerException
                  &amp;&amp; cm.getActiveNetworkInfo() != null
                  &amp;&amp; ((cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI) != null &amp;&amp; cm.getNetworkInfo(
                          ConnectivityManager.TYPE_WIFI).isConnected()));
  
  }
  </code></pre>
  
  <p>Any thoughts why this happen? I can't debug it because it's only occasional from bugs reports. Only solution I see is to put it into try catch block. Thanks.</p>