Cómo observar la conectividad a Internet en Android – Tutoriales de Android Studio

En este video aprenderá cómo monitorear si el usuario está conectado a Internet o no. Funciona con proyectos Compose y XML 🙂 ⭐ Obtenga la certificación para su trabajo futuro ⭐ Ahorre innumerables horas de tiempo ⭐ Garantía de devolución del 100 % del dinero en 30 días ⭐ Conviértase en un desarrollador profesional de Android ahora: suscríbase a mi boletín informativo GRATUITO para Android normal, Kotlin y Consejo de Arquitectura! Únase a este canal para obtener acceso a los beneficios: Obtenga el código fuente de este video aquí: Únase a mi servidor de Discord: Consejos de codificación regulares en mi página de Instagram: Consulte mi GitHub: ¿Le gusta mi contenido gratuito? Aquí puedes ofrecerme un café:

Compruebe también

Desarrollo de aplicaciones web móviles (Android studio)

Mi primera aplicación.. Aplicación móvil de restaurante.

41 comentarios

  1. Nice video…. Thank u so much for this….

  2. Thank You for making video in Kotlin 🙏

  3. How to pass initial state in non-compose application?

  4. Thank you for your superb explanation ! You're certainly the best YouTube's Android guy !

  5. Hi Philip thanks for this video. I am trying to implement this in my application that uses hilt for DI. I have a custom Interceptor that adds some auth header before the request is being processed, but my application crashes as soon as it opens. How can I catch the error and send it to the user? Thank you

  6. The observe() function registers a new network callback every time we try to observe it and returns a cold flow. We can prevent this by converting the cold flow into a hot flow using the `shareIn` or `stateIn` operators. We can add a property to the `class NetworkConnectivityObserver` like this:

    val status: Flow<Status> = observe().stateIn(scope, WhileSubscribed(), Status.Unavailable) // Injected scope

    Or creating a `class NetworkStatusRepository(CoroutineScope, ConnectivityObserver)` which creates a property like above will be better.

  7. Thank you for your great content, however I seem to get an issue with this – my App doesn't fire when you first hook up the flow and you have no internet – I was expecting it to show 'Unavailable' as it does with 'Available'…

  8. how to observe it without compose collectasstate is not the option available in normal xml

  9. Hey, great video, I've tried to implement it but it seems like onUnavailable is not getting triggered? I've tried and turned off wifi and data in emulator, started the app and no log message showed up. Then when I turned on Wifi, Available status got sent to the channel and then when I turned it off, Lost status got sent. But never the Unavailable.

  10. If I have to ping google to check whether connection really exists or not, how should I do it?

  11. This is timely. Thanks a lot for the thorough breakdown on how and why.

  12. @8:10 you mention needing to use ViewModelFactory to inject the context using Hilt for the ConnectivityObserver, but is the ViewModelFactory actually needed in that case? Would it not just be injected in the Hilt Module and then injected into the Activity or Fragment (because it contains a reference to the Context) and then send messages to the ViewModel via an exposed channel or flow?

    What I'm asking is that the ConnectivityObserver would be injected into the Activity/Fragment and not the ViewModel because of the applicationContext dependency in ConnectivityObserver. Wouldn't injecting the ConnectivtyObserver into the ViewModel cause memory leaks due to the dependency on applicationContext? Or is the applicationContext always valid and does not change on config changes?

    Would it make more sense to inject the ConnectivityObserver into the fragment/activity and then send messages to the ViewModel on the changes of network state?

  13. Hi, this crushes app if you turn off and on and turn it back while observing some state.

  14. Hi Philipp, thanks for the awesome video, one question, if we were to implement this in ViewModel, we would need to extend AndroidViewModel for getting the application context, is there a way we can do this with extending the simple ViewModel class?

  15. Hey bro, Thank you so much for the great content 🙏

    One question, can we not use trySend() instead of launch { send( ) }

    or is it ultimately the same thing


  16. Hi, I have a doubt. For eg: fun getUsers(): Flow<List<ApiUser>> and suspend fun getUsers(): List<ApiUser>. Here both the function will fetch the list of data from the API. What are the benefits of converting API data or List into FLOW? Also, my app does not retrieve streams of data like the stock market or video streaming app. Do I really need to use Flow?

  17. Android боклук 😂 Iso iphone 🤘

  18. Nice Explanation! however I'd like to highlight that The android ConnectivityManager API only notifies the clients about the Network Status (available, Lost, etc…) wether your device is connected to a network or not and does not reflect the actual Internet connectivity.
    The only way to check if the device has access to Internet is through a HTTP request that returns a valid HTTP status code.

  19. Hey bro I have a question, Have you thought about doing an updated augmented reality course, perhaps with the scene view library on udemy or I don't know if on any platform? Because the scene form is no longer maintained and it is a world with a lot of potential but little explored. Thank you.

  20. What's your thought on creating a state based application like implementing FSM(Finite State Machine) in its brother ?

  21. *Mrs Charlotte is legit and her method works like magic I keep on earning every single week with her new strategies *

  22. Thank you sir for the great content, I just want to know where does the observer fit in the clean architecture design

  23. Phillip i was finding a solution like this, thanks brother.

  24. Awesome tutorial Phill

  25. I try these code but these callback is not work(apart from onAvailable)..

  26. Hi Philipp thank you so mush great work ! Please if you Can one day make a video about how to use okhttp authenticator, i never find video or tutorial that talking about it on thé nice way, which you the best ❤️💪

  27. Very nice. Exactly what I needed right now 😂


  29. Wouldn't it be better to use StateFlow, less and cleaner code?

  30. It's a useful demo for handling the context depend resource by callbackflow ❤️

  31. Connectivity means nothing, if it is connected not the fact user have internet

  32. please tell me how to create game animation
    please tell me about graphics
    canvas unity, agdk

  33. Great tutorial! I would love to have a video which will expand this knowledge to Ethernet connection observer via broadcast receiver for Android boxes!

  34. Much needed 💙

  35. I am having an Issue to when I add the Permissions for the Network_State. it Informs me even after adding to manifest permission is still missing

  36. How can I convert this code to a service, to monitoring all mi app no only one activity? 🤔

  37. can u make video about bazel build tools

  38. CallbackFlow can directly use “offer” to provide data, you don’t need to use “send” because you didn’t change the coroutine context.

  39. What if you are connected to a network and internet is not working.😉

  40. That's Philip Lackner's way of programming ⭐ it will be great if we can add backward compatibility to it and make it even better solution

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *