Open Another Activity When There Is No Network

125 Views Asked by At

I want to open another activity which displays no internet connection if there is no network. Can I do that? please help.

1

There are 1 best solutions below

0
amandeep aggarwal On
inline fun Context.withNetwork(isToNotify: Boolean = true, block: () -> Unit) {
    val connectivityManager = this.getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager
    connectivityManager?.let {
        val netInfo = it.activeNetworkInfo
        val isConnected = netInfo != null && netInfo.isConnectedOrConnecting
        if (isToNotify && !isConnected){
            toast(R.string.message_no_network_message)
             //Use Here Intent For Another Activity

        }else{
            block()
        }
    }
}