title: How to keep observe internet access in app background
body: <p>I have one method that must be execute when device can access to internet(can ping to 8.8.8.8, not just connect or available). What method should I use to detect internet access(can/cannot reach to server) both app running in foreground and background?</p>
  
  <p>I use NetworkCallback(onAvailable() and onLost()) with JobService(by registerNetworkCallback in onStartJob()). It can perform internet connection correctly but not internet access.</p>
  
  <pre><code>class MyNetworkCallback() : ConnectivityManager.NetworkCallback() {
  
      override fun onAvailable(network: Network?) {
          super.onAvailable(network)
          Log.i("ConnectionStatus", "Connected")
          // perform my method
      }
  
      override fun onLost(network: Network?) {
          super.onLost(network)
          Log.i("ConnectionStatus", "Disconnected")
      }
  }
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/1560788/how-to-check-internet-access-on-android-inetaddress-never-times-out/50962092">How to check internet access on Android? InetAddress never times out</a> 
  This topic is good about how to check internet access by many method, but I do not know how to integrate this method to JobService for keep observe internet access to check device can reach to server or not.</p>
  
  <p>What I want:</p>
  
  <ol>
  <li><p>when app running in both foreground and background, device connect to internet and device can access to server ==> perform method()</p></li>
  <li><p>when app running in both foreground and background, device connect to internet BUT device cannot access to server ==> NOT perform method()</p></li>
  <li>when app running in both foreground and background, device not connect to internet and device cannot access to server ==> NOT perform method()</li>
  </ol>