2014-09-19 62 views
0

我想检测网络漫游,但Windows Phone 8和8.1上没有Internet连接。我用这个代码,以确定用户是否是在漫游:当没有Internet连接时检测网络漫游

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

有了这个代码,很容易找到,如果手机是在当有上网漫游。但是,如果没有连接并且ConnectionProfile返回null,则会发生此问题。我搜索了互联网和堆栈溢出检测网络漫游,但没有结果。建议使用MNC和MCC,但Windows Phone不提供此类信息或任何更详细的网络信息。我没有找到类似Android telephonyManager.isNetworkRoaming()的函数。

是否有一个函数,API或方法来检测用户是否在漫游中,但是当Internet连接关闭?

回答

0

你可以试试这个,

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

+0

这个库是在我的面前,但它不是我想要的东西。从这我只能知道,如果用户允许电话连接(WiFi,GSM等),但不通知它是否真的在漫游。 – 2014-09-19 11:26:12

+0

DeviceNetworkInformation.IsCellularDataRoamingEnabled.ToString()这不起作用?? – 2014-09-19 11:28:16

+0

当你关闭数据漫游时,这个属性会让你失败。为了确定它是否在Internet连接时漫游,我使用您的答案中的链接中描述的连接配置文件。目前的问题是确定没有可用互联网的漫游。 – 2014-09-19 12:41:03