Windows Phone 8.1: check your internet connection

How do I know if my phone has an internet connection? (Whether it’s WiFi or data)

Sometimes your phone connects to WiFi without an internet connection, such as HotSpots. So I want the code to know if the phone is connected to the Internet.

+5
source share
4 answers

You can just try:

if (NetworkInformation.GetInternetConnectionProfile() == null) { //no connection } 

As you can see in this documentation msdn: NetworkInformation.GetInternetConnectionProfile

It will return null if "there is no connection profile with a suitable connection"

You can also check the visibility of the Internet access level as follows: NetworkInformation.GetInternetConnectionProfile().GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess

I think this will work in a universal application.

+2
source

The below method works for me simply to check if the device is connected to the Internet or even in the universal Windows application. After creating the connection class, you can simply use it anywhere, simply by creating an instance of this class ...

 public class Connection { public bool CheckInternetAccess() { var connectionProfile = NetworkInformation.GetInternetConnectionProfile(); var HasInternetAccess = (connectionProfile != null && connectionProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess); return HasInternetAccess; } } 

To use this class is simple ..

  Connection objConnection = new Connection(); if(objConnection.CheckInternetAccess()==true) { //todo } else {//todo} 
+1
source

What you want is an involuntary portal, which is pretty much the page that users connect to to check if their internet connection works, can be explained in more detail here .

These open source projects look promising:

Good luck

0
source

Please consider checking the internet in the background thread.

 if (await Task.Run(() =>NetworkInterface.GetIsNetworkAvailable()) { //Wifi or Cellular } else { // No internet } 
0
source

Source: https://habr.com/ru/post/1209881/


All Articles