Observing Network Connection State using Jetpack Compose - Android

Поделиться
HTML-код
  • Опубликовано: 19 окт 2024
  • In this video, we will create an app that observes when the network connectivity changes using Jetpack Compose and Kotlin
    Repository: github.com/dan...
    Let's connect 🤗:
    / daniel-atitienei
    Blog: / daniel.atitienei
    Do you like my content? Here you can support me with a coffee ☕:
    www.buymeacoff...

Комментарии • 25

  • @manticomar1146
    @manticomar1146 Месяц назад +1

    Ur a genius

  • @KingFuYouTube
    @KingFuYouTube 2 месяца назад +4

    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
    }

  • @paulotarolalopez
    @paulotarolalopez 2 месяца назад

    please can you make a tutorial on bluetooth with jetpack compose

  • @Salehalanazi-7
    @Salehalanazi-7 2 месяца назад

    Keep going 🫶🏻

  • @omo_dev
    @omo_dev 2 месяца назад

    good video❤, in which layer can be this code in clear architecture?

    • @daniel.atitienei
      @daniel.atitienei  2 месяца назад

      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

    • @omo_dev
      @omo_dev 2 месяца назад

      @@daniel.atitienei thanks❤

    • @daniel.atitienei
      @daniel.atitienei  2 месяца назад

      You're welcome!

  • @antonvitser5667
    @antonvitser5667 2 месяца назад

    Наверное, стоит еще указывать и permission для этого дела.

  • @srisai1200
    @srisai1200 2 месяца назад

    Hi already available code regarding network connection or not , in these code any specification sir

  • @Muhammad-Shafqat
    @Muhammad-Shafqat 2 месяца назад

    Love it❤ bro can u make a video on that show nearby wifi network and and show how is cnnected to my wifi

    • @daniel.atitienei
      @daniel.atitienei  2 месяца назад +1

      Will try!

    • @Muhammad-Shafqat
      @Muhammad-Shafqat 2 месяца назад

      @@daniel.atitienei Thank u Sir

    • @Muhammad-Shafqat
      @Muhammad-Shafqat 2 месяца назад

      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
      }

  • @kahrbaa
    @kahrbaa 2 месяца назад +1

    if i work wifi but not have internet what will show?

    • @daniel.atitienei
      @daniel.atitienei  2 месяца назад +2

      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

    • @kahrbaa
      @kahrbaa 2 месяца назад +1

      @@daniel.atitienei thanks, keep going ❤️❤️

  • @natanell777
    @natanell777 2 месяца назад

    Why you are not using Broadcast Receiver?

    • @daniel.atitienei
      @daniel.atitienei  2 месяца назад

      In this case is not really needed and for directly observing this in our UI I find this way more suitable.

    • @manticomar1146
      @manticomar1146 Месяц назад

      After sdk 24 broadcast receivers don't work for this

  • @aminsakha155
    @aminsakha155 2 месяца назад

    bro, work on your energy