File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed
Jetcaster/app/src/main/java/com/example/jetcaster/ui Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ package com.example.jetcaster.ui
1818
1919import android.content.Context
2020import android.net.ConnectivityManager
21+ import android.net.NetworkCapabilities
22+ import android.os.Build
2123import androidx.compose.material.AlertDialog
2224import androidx.compose.material.Text
2325import androidx.compose.material.TextButton
@@ -44,12 +46,18 @@ fun JetcasterApp() {
4446 }
4547}
4648
47- // TODO: Use a better way to check internet connection
4849@Suppress(" DEPRECATION" )
4950private fun checkIfOnline (context : Context ): Boolean {
5051 val cm = context.getSystemService(Context .CONNECTIVITY_SERVICE ) as ConnectivityManager
51- val activeNetwork = cm.activeNetworkInfo
52- return activeNetwork?.isConnectedOrConnecting == true
52+
53+ return if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
54+ val capabilities = cm.getNetworkCapabilities(cm.activeNetwork) ? : return false
55+
56+ capabilities.hasCapability(NetworkCapabilities .NET_CAPABILITY_INTERNET ) &&
57+ capabilities.hasCapability(NetworkCapabilities .NET_CAPABILITY_VALIDATED )
58+ } else {
59+ cm.activeNetworkInfo?.isConnectedOrConnecting == true
60+ }
5361}
5462
5563@Composable
You can’t perform that action at this time.
0 commit comments