how-to-check-if-internet-connection-is-enabled-in-android using Kotlin - Joklinz-Tech

Latest

Home Of Tech news,jobs and android tutorials

Monday 12 February 2018

how-to-check-if-internet-connection-is-enabled-in-android using Kotlin






override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_register)
    val cm = applicationContext            .getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
    val activeNetwork = cm.activeNetworkInfo

if (null != activeNetwork) {
    if(activeNetwork.getType() == ConnectivityManager.TYPE_WIFI)
        toast("You are connected to a Wifi Network")
    if(activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE)
        toast("You are connected to a Mobile Network")
}
else    toast("Your not connected to to the internet")

No comments:

Post a Comment