title: Check internet connectivity android in kotlin
body: <p>I tried the answer from <a href="https://stackoverflow.com/questions/1560788/how-to-check-internet-access-on-android-inetaddress-never-times-out">this</a> (the accepted answer). I can use the "PING" method but the UI went black since it says it will block the UI Thread. It didn't look good and was disturbing so I tried to use the second method "Connect to a Socket on the Internet" but I don't know how to use the class in Kotlin. </p>
  
  <p>This is the result of converted Java to kotlin by android studio</p>
  
  <pre><code>package com.mockie.daikokuten.helpers
  
  import android.os.AsyncTask.execute
  import android.os.AsyncTask
  import java.io.IOException
  import java.net.InetSocketAddress
  import java.net.Socket
  
  
  internal class InternetCheck(private val mConsumer: Consumer) : AsyncTask&lt;Void, Void, Boolean&gt;() {
  interface Consumer {
      fun accept(internet: Boolean?)
  }
  
  init {
      execute()
  }
  
  override fun doInBackground(vararg voids: Void): Boolean? {
      try {
          val sock = Socket()
          sock.connect(InetSocketAddress("8.8.8.8", 53), 1500)
          sock.close()
          return true
      } catch (e: IOException) {
          return false
      }
  
  }
  
  override fun onPostExecute(internet: Boolean?) {
      mConsumer.accept(internet)
  }
  }
  </code></pre>
  
  <p>but <strong>I DONT KNOW HOW TO USE IT</strong>. I tried this way:</p>
  
  <pre><code>InternetCheck{ internet-&gt; Log.d("test", "asdasdas") }
  </code></pre>
  
  <p>It didnt work and results in an error. It says I have to pass "Consumer". </p>
  
  <p>My question is <strong>How to use that class</strong>?</p>