Mateusz Puwałowski
Mateusz Puwałowski

Reputation: 121

How to check internet connection status over 3G connection?

I have the following method:

public static bool IsNetworkConnected()
{
    ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
    IReadOnlyList<ConnectionProfile> connectionProfile = NetworkInformation.GetConnectionProfiles();
    if (InternetConnectionProfile == null)
        return false;
    else
        return true;
}

It works fine when I'm connected to the internet in a typical way - via LAN cable or Wi-Fi. When I'm using my 3G USB modem it returns false (InternectConnectionProfile is null). Why is that? How can I fix it?

Upvotes: 2

Views: 3526

Answers (3)

Igor Kulman
Igor Kulman

Reputation: 16361

Try

public static bool IsConnectedToInternet()
{
        ConnectionProfile connectionProfile = NetworkInformation.GetInternetConnectionProfile();
        return (connectionProfile!=null && connectionProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess);
}

Upvotes: 2

Demir
Demir

Reputation: 1837

You may consider pinging a server on the internet. This is not the 100% answer to your question but may be helpful from a different point of view.

using System.Net;
using System.Net.NetworkInformation;

using (Ping Packet = new Ping()) 
{
    if (Packet.Send(IPAddress.Parse(IP), 1000, new byte[] { 0 }).Status ==   IPStatus.Success))
    {
       // ...
    }
}

Upvotes: 4

Related Questions