I want to get Network State means whether the Connected network has internet connection in Jetpack Compose. How to achieve it
val connectivityManager
= getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetworkInfo = connectivityManager.getActiveNetworkInfo()
Text(
if(
activeNetworkInfo != null && activeNetworkInfo.isConnected()
) "Connected"
else "Disconnected"
)
This is a Composable which displays the state of the network. As correctly pointed out in the comment above, JC is focused more on the UI, so all the rest of the stuff is still the same old Android way. JC just efficiensizes(?) the GUI development