【问题标题】:Detect network roaming when there is no Internet connection在没有 Internet 连接时检测网络漫游
【发布时间】:2014-09-19 07:50:07
【问题描述】:

我想检测网络漫游,而 Windows Phone 8 和 8.1 上没有 Internet 连接。我使用此代码来确定用户是否处于漫游状态:

ConnectionProfile profile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
        if (profile == null)
            return false;
        else
            return profile.GetConnectionCost().Roaming;

使用此代码,当有 Internet 访问时,很容易找到手机是否处于漫游状态。但是,当没有连接并且 ConnectionProfile 返回 null 时,就会出现问题。我搜索了 Internet 和 Stack Overflow 以检测网络漫游,但没有结果。建议使用 MNC 和 MCC,但 Windows Phone 不提供此类信息或任何更详细的网络信息。我没有找到像 Android telephonyManager.isNetworkRoaming() 这样的函数。

是否有功能、API 或方法可以检测到用户正在漫游,但当 Internet 连接断开时?

【问题讨论】:

    标签: windows-phone-8 windows-runtime windows-phone-8.1


    【解决方案1】:

    你可以试试这个,

    using Microsoft.Phone.Net.NetworkInformation;
    private void button1_Click(object sender, RoutedEventArgs e)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append("Network available:  ");
        sb.AppendLine(DeviceNetworkInformation.IsNetworkAvailable.ToString());
        sb.Append("Cellular enabled:  ");
        sb.AppendLine(DeviceNetworkInformation.IsCellularDataEnabled.ToString());
        sb.Append("Roaming enabled:  ");
        sb.AppendLine(DeviceNetworkInformation.IsCellularDataRoamingEnabled.ToString());
        sb.Append("Wi-Fi enabled:  ");
        sb.AppendLine(DeviceNetworkInformation.IsWiFiEnabled.ToString());
        MessageBox.Show(sb.ToString());
    }
    

    您可能还会发现这很有用http://msdn.microsoft.com/library/windows/apps/jj207005%28v=vs.105%29.aspx

    【讨论】:

    • 我知道这个库,但它并不是我想要的。从这里我只能知道如果用户允许手机建立连接(WiFi、GSM 等),但不通知它是否真的在漫游。
    • DeviceNetworkInformation.IsCellularDataRoamingEnabled.ToString() 这不起作用??
    • 当你关闭数据漫游这个属性会给你假。为了确定当有 Internet 连接时它是否正在漫游,我使用您答案中链接中描述的连接配置文件。问题是在没有可用 Internet 的情况下确定漫游。
    猜你喜欢
    • 1970-01-01
    • 2019-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-15
    • 2013-07-23
    • 2010-10-10
    相关资源
    最近更新 更多