I'm developing Windows Phone 8 application. In this application, I have to connect to the server to get the data.
So Before connecting to the server, I want to check whether the internet connection available or not to the device. If the internet connection is available, then only I'll get the data from the server, Otherwise I'll show an error message.
Please tell me how to do this in Windows Phone 8.
NetworkInterface.GetIsNetworkAvailable()
returns the status of the NICs.
Depending on the status you can ask if the connectivity is established by using:
ConnectionProfile
-Class of Windows Phone 8.1 which uses the enum NetworkConnectivityLevel
:
This code should do the trick.
bool isConnected = NetworkInterface.GetIsNetworkAvailable();
if (isConnected)
{
ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
NetworkConnectivityLevel connection = InternetConnectionProfile.GetNetworkConnectivityLevel();
if (connection == NetworkConnectivityLevel.None || connection == NetworkConnectivityLevel.LocalAccess)
{
isConnected = false;
}
}
if(!isConnected)
await new MessageDialog("No internet connection is avaliable. The full functionality of the app isn't avaliable.").ShowAsync();