Windows Phone 7 開發之檢查手機網絡

webphp 14年前發布 | 14K 次閱讀 Windows Phone開發 移動開發 Windows Phone

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;
using System.Net.NetworkInformation;
using Microsoft.Phone.Net.NetworkInformation;

namespace checknet { public partial class MainPage : PhoneApplicationPage { private bool networkIsAvailable; private NetworkInterfaceType _currentNetworkType; //網絡連接的類型

    public MainPage()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        networkIsAvailable = Microsoft.Phone.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable();//當前網絡是否可用
        _currentNetworkType = Microsoft.Phone.Net.NetworkInformation.NetworkInterface.NetworkInterfaceType;//獲取當前網絡的類型

        if (networkIsAvailable)
        {
            Message.Text = "聯網狀態";
            Message.Background = new SolidColorBrush(Colors.Green);
        }
        else
        {
            Message.Text = "斷網狀態";
            Message.Background = new SolidColorBrush(Colors.Red);
        } 

        switch (_currentNetworkType)
        {
            case NetworkInterfaceType.MobileBroadbandCdma:
                netname.Text = "Cdma網絡";
                break;
            case NetworkInterfaceType.MobileBroadbandGsm:
                netname.Text = "Csm網絡";
                break;
            case NetworkInterfaceType.Wireless80211:
                netname.Text = "Wireless網絡";
                break;
            case NetworkInterfaceType.Ethernet:
                netname.Text = "Ethernet網絡";
                break;
            case NetworkInterfaceType.None:
                netname.Text = "網絡不可用";
                break;
            default:
                netname.Text = "其他的網絡";
                break;
        }       
    }
}

}</pre>

 本文由用戶 webphp 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!