Windows phone 8 在没有Internet连接时检测网络漫游
我想在Windows Phone 8和8.1上没有Internet连接时检测网络漫游。我使用此代码确定用户是否处于漫游状态:Windows phone 8 在没有Internet连接时检测网络漫游,windows-phone-8,windows-runtime,windows-phone-8.1,Windows Phone 8,Windows Runtime,Windows Phone 8.1,我想在Windows Phone 8和8.1上没有Internet连接时检测网络漫游。我使用此代码确定用户是否处于漫游状态: ConnectionProfile profile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile(); if (profile == null) return false; else
ConnectionProfile profile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
if (profile == null)
return false;
else
return profile.GetConnectionCost().Roaming;
有了这段代码,就很容易发现当有互联网接入时,手机是否处于漫游状态。但是,当没有连接且ConnectionProfile返回null时,就会出现问题。我搜索了Internet和堆栈溢出以检测网络漫游,但没有结果。有人建议使用MNC和MCC,但Windows Phone没有提供此类信息或任何更详细的网络信息。我没有找到像Android telephonyManager.isNetworkRoaming这样的函数
是否有一个函数、API或方法来检测用户是否处于漫游状态,但当Internet连接断开时?您可以尝试一下
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());
}
您可能也会发现这个有用的我知道这个库,但它并不完全是我想要的。从这一点我只能知道,如果用户允许手机连接WiFi、GSM等,但不通知它是否真的处于漫游状态。DeviceNetworkInformation.IsCellularDataRoamingEnabled.ToString这不起作用??当您关闭数据漫游时,此属性将为false。为了确定有Internet连接时是否漫游,我使用您答案中链接中描述的连接配置文件。关键在于确定在没有可用互联网的情况下漫游。