title: What will be the context for CONNECTIVITY_SERVICE in Fragment?
body: <p>What will be the context for CONNECTIVITY_SERVICE in a Fragment? I have checked getActivity also but it is giving an error.</p>
  <pre><code>public boolean isOnline() {
      ConnectivityManager connectionManager = (ConnectivityManager) 
          getSystemService(Context.CONNECTIVITY_SERVICE);
      try {
          if (connectionManager.getActiveNetworkInfo().isConnected()) {
              Log.d(&quot;ConStatus&quot;, &quot;Data Connection On&quot;);
              return true;
          } else {
              Log.d(&quot;ConStatus&quot;, &quot;Data Connection off&quot;);
              return false;
          }
      } catch (NullPointerException e) {
          Log.i(&quot;ConStatus&quot;, &quot;No Active Connection&quot;);
          return false;
      }
  }
  </code></pre>