how to check InternetConnection in wp7?

2019-06-16 04:01发布

i want to check internet connection in my application.but, its not displaying properly.

i am using this code for internet connection:

 NetworkInterface.GetIsNetworkAvailable();

in this code always return true value.if net available or not available return true only.

if anyone know tell me idea to do this.

thanks.

3条回答
倾城 Initia
2楼-- · 2019-06-16 04:32

Check NetworkInterfaceType. If Internet is available then It should be other than None

 return (Microsoft.Phone.Net.NetworkInformation.NetworkInterface.NetworkInterfaceType != 
 Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.None);
查看更多
闹够了就滚
3楼-- · 2019-06-16 04:52

Yes NetworkInterface.GetIsNetworkAvailable() will always return true on windows phone emulator you can try below code to detect network availability.

using Microsoft.Phone.Net.NetworkInformation;    
    if (DeviceNetworkInformation.IsNetworkAvailable)
    {
    MessageBox.Show("network available") ;              
    }
    else
    {
    MessageBox.Show("No network.") ;   
    }
查看更多
▲ chillily
4楼-- · 2019-06-16 04:54

In the Windows Phone Emulator it's correct that NetworkInterface.GetIsNetworkAvailable() will always return true. Even if your PC has no internet connection, the emulator counts the local/internal connection to your PC.

The return value will be false if you test your application on a real device and switch it e.g. in flight-mode.

查看更多
登录 后发表回答