← Tutti gli articoli

Network Awareness ( Windows Phone 7 )

22 April 2011  ·  Windows Phone 7 · Article  ·  859 visite

How to detect the type, speed and the network state changes in your Windows Phone 7 mobile device.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
namespace WindowsPhoneApplication_WiFi
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            System.Net.NetworkInformation.NetworkChange.NetworkAddressChanged += new System.Net.NetworkInformation.NetworkAddressChangedEventHandler(NetworkChange_NetworkAddressChanged);
        }
        void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
        {
            CheckWiFiStatus();
        }
       
        protected void CheckWiFiStatus()
        {
            try
            {
                switch (Microsoft.Phone.Net.NetworkInformation.NetworkInterface.NetworkInterfaceType)
                {
                    case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.None:
                        textBlock1.Text = "None";
                        break;
                    case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Wireless80211:
                        
                        textBlock1.Text = "Wireless80211";
                        break;
                    case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Ethernet:
                        
                        textBlock1.Text = "Ethernet";
                        break;
                    case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.MobileBroadbandGsm:
                        
                        textBlock1.Text = "MobileBroadbandGsm";
                        break;
                    case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.MobileBroadbandCdma:
                        
                        textBlock1.Text = "MobileBroadbandCdma";
                        break;
                }
            }
            catch (Exception ecc)
            {
                MessageBox.Show("Problem in the Network status check:" +ecc.ToString());
            }
        }
    }
}
Si è verificato un errore imprevisto. Ricarica

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.