I forgot to check for that in the video, but to do that you can have another variable in the getCurrentConnectivityState that checks if the network has NetworkCapabilities.NET_CAPABILITY_VALIDATED
suspend fun getNearbyWifiNetworks(): List { val response = context.getNearbyWifiNetworks() return response } fun Context.getNearbyWifiNetworks(): List { val wifiManager = applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager if (ContextCompat.checkSelfPermission( this, Manifest.permission.ACCESS_FINE_LOCATION ) != PackageManager.PERMISSION_GRANTED ) { return emptyList() } wifiManager.startScan() return wifiManager.scanResults }
Thanks! You can put all the code in the data layer > network excluding the @Composable one. That one you can put it in the presentation layer in a package called util
this is what I have: fun hasConnection(context: Context): Boolean { val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager val capabilities = connectivityManager.getNetworkCapabilities(connectivityManager.activeNetwork) if (capabilities != null) { if (capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) { return true } } return false }
Ur a genius
if i work wifi but not have internet what will show?
I forgot to check for that in the video, but to do that you can have another variable in the getCurrentConnectivityState that checks if the network has NetworkCapabilities.NET_CAPABILITY_VALIDATED
@@daniel.atitienei thanks, keep going ❤️❤️
Hi already available code regarding network connection or not , in these code any specification sir
Why you are not using Broadcast Receiver?
In this case is not really needed and for directly observing this in our UI I find this way more suitable.
After sdk 24 broadcast receivers don't work for this
Love it❤ bro can u make a video on that show nearby wifi network and and show how is cnnected to my wifi
Will try!
@@daniel.atitienei Thank u Sir
suspend fun getNearbyWifiNetworks(): List {
val response = context.getNearbyWifiNetworks()
return response
}
fun Context.getNearbyWifiNetworks(): List {
val wifiManager =
applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
if (ContextCompat.checkSelfPermission(
this,
Manifest.permission.ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED
) {
return emptyList()
}
wifiManager.startScan()
return wifiManager.scanResults
}
good video❤, in which layer can be this code in clear architecture?
Thanks! You can put all the code in the data layer > network excluding the @Composable one. That one you can put it in the presentation layer in a package called util
@@daniel.atitienei thanks❤
You're welcome!
this is what I have:
fun hasConnection(context: Context): Boolean {
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val capabilities = connectivityManager.getNetworkCapabilities(connectivityManager.activeNetwork)
if (capabilities != null) {
if (capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) {
return true
}
}
return false
}
Keep going 🫶🏻
I will thanks!
please can you make a tutorial on bluetooth with jetpack compose
Sure
bro, work on your energy
I will 😅
Don't be rude
Наверное, стоит еще указывать и permission для этого дела.