How to monitor internet connection in

RajeshNegiRajeshNegi USMember ✭✭

Hey i want to implement this feature in my android application in which--
when the internet is off it will give Internet is off with refresh method in snackbar
other wise the application will run.
In the running application if internet is not there it should give internet if off refresh..
i have implemented this at application start but unable to do continuously......!!!!!!!!


  • VarunBabuSVarunBabuS INMember ✭✭✭

    hi @RajeshNegi for implementation of asset tracking where we capture geo-coordinates in background i used the following link for reference using the same concept may be at regular intervals you can may be using some components to detect internet connectivity and alert user appropriately

  • RajeshNegiRajeshNegi USMember ✭✭

    I want to implement Broadcast Receiver ....
    which takes the information from android os

  • cwphillicwphilli USMember ✭✭✭

    Below is a solution that provides the ability to subscribe to events, i.e. ConnectivityChanged.

    Personally I added this via nuget in my packages.config:

  • cwphillicwphilli USMember ✭✭✭
        private static void CurrentOnConnectivityTypeChanged(object sender, ConnectivityTypeChangedEventArgs connectivityTypeChangedEventArgs)
            if (!connectivityTypeChangedEventArgs.IsConnected) return;
            var availableConnections = string.Join(",", connectivityTypeChangedEventArgs.ConnectionTypes);
            Console.WriteLine($"Connections available: {availableConnections}");
            // TODO: store available connections?
        private static void CurrentOnConnectivityChanged(object sender, ConnectivityChangedEventArgs connectivityChangedEventArgs)
            if (connectivityChangedEventArgs.IsConnected)
                Console.WriteLine($"Connectivity has been restored");
                // TODO: maintain connection status"
        private static void SetupConnectionListeners()
            CrossConnectivity.Current.ConnectivityChanged += CurrentOnConnectivityChanged;
            CrossConnectivity.Current.ConnectivityTypeChanged += CurrentOnConnectivityTypeChanged;
  • RajeshNegiRajeshNegi USMember ✭✭

    where i need to put this code..

Sign In or Register to comment.