【问题标题】:C# Read Windows Mobile Broadband connection propertiesC# 读取 Windows Mobile 宽带连接属性
【发布时间】:2013-09-02 16:34:06
【问题描述】:

首先,这是背景:

我们有一个 Windows 窗体应用程序(用 C#、.NET Framework 3.5 编写),目前在完整的 Windows 7 平板电脑上运行,它内置了一个用于数据连接的 3G 模块。数据连接在 Windows 中配置为普通的移动宽带连接(因此 Windows 自己管理连接),连接显示在控制面板 > 网络和 Internet > 网络连接中,并且工作正常 - 应用程序能够通过互联网与我们的网络服务。我们将在未来的某个时间转移到不同的设备(可能是基于 Windows 8 的完整平板电脑)。

现在,我需要做的是读取此移动宽带连接的连接状态;即获取信号强度和运营商名称(例如 Vodafone UK)。我找到了一种方法来使用 Windows 7 SDK 的移动宽带 API 部分(请参阅 herehere),但这似乎是特定于操作系统的,因为它在 Windows 8 上不起作用 - 或至少不是我这里的设备。

是否有使用 .NET 框架读取移动宽带连接属性的通用方法?

另外,有谁知道 Windows 8 SDK 包含移动宽带 API,例如我目前使用的 Windows 7?

提前致谢。

更新 - 我现在可以在一系列不同的 Win 7 / Win 8 设备上使用它。即使是联想设备也可以正常工作。我将发布主要位(读取连接状态、配置连接、检查 SIM 状态)的示例代码作为答案;代码有点太长,无法回答问题,烦人。

【问题讨论】:

  • 我已经添加了大部分我最终用于测试的代码作为下面的答案。您自己的代码可能不会被 MessageBox 乱七八糟,但希望其他人会发现这些示例很有用。
  • 嗨,你是如何让它在 Windows 8 上工作的? mbnInfMgrInterface = null,当我在 Windows 8 上尝试相同的操作时...我需要额外安装还是 Interop.MbnApi.dll 足够?
  • 我尝试过的所有 Win 8 设备都返回了 IMbnInterfaceManager - 尽管它在没有移动宽带适配器的任何设备上都无法工作(例如我的台式电脑)。它是什么设备,在 Windows 中手动配置时适配器是否工作?
  • 嘿,Paul F,感谢您的回答,我得到了它的工作。我的错误,我只是复制粘贴您的代码,然后看到有些情况没有处理“什么都不做”......我现在可以在 Windows 8 上工作。我的平板电脑上没有视觉工作室,所以我无法准确测试......我认为 imbninterfacemanager 为空,但它不是......对不起,我的错误......赞成你的回应......

标签: c# .net windows winforms mobile-broadband-api


【解决方案1】:

以编程方式配置连接(您将需要 APN 详细信息):

try
        {
            MbnInterfaceManager mbnInfMgr = new MbnInterfaceManager(); 
            IMbnInterfaceManager mbnInfMgrInterface = mbnInfMgr as IMbnInterfaceManager;
            if (mbnInfMgrInterface != null)
            {
                IMbnInterface[] mobileInterfaces = mbnInfMgrInterface.GetInterfaces() as IMbnInterface[];
                if (mobileInterfaces != null && mobileInterfaces.Length > 0)
                {
                    // Just use the first interface
                    IMbnSubscriberInformation subInfo = mobileInterfaces[0].GetSubscriberInformation();

                    if (subInfo != null)
                    {
                        SIMNumber = subInfo.SimIccID;
                        // Get the connection profile
                        MbnConnectionProfileManager mbnConnProfileMgr = new MbnConnectionProfileManager();
                        IMbnConnectionProfileManager mbnConnProfileMgrInterface = mbnConnProfileMgr as IMbnConnectionProfileManager; 
                        if (mbnConnProfileMgrInterface != null)
                        {
                            bool connProfileFound = false;
                            string profileName = String.Empty;

                            try
                            {
                                IMbnConnectionProfile[] mbnConnProfileInterfaces = mbnConnProfileMgrInterface.GetConnectionProfiles(mobileInterfaces[0]) as IMbnConnectionProfile[];

                                foreach (IMbnConnectionProfile profile in mbnConnProfileInterfaces)
                                {
                                    string xmlData = profile.GetProfileXmlData();

                                    if (xmlData.Contains("<SimIccID>" + SIMNumber + "</SimIccID>"))
                                    {
                                        connProfileFound = true;
                                        bool updateRequired = false;

                                        // Check if the profile is set to auto connect
                                        XmlDocument xdoc = new XmlDocument();
                                        xdoc.LoadXml(xmlData);

                                        profileName = xdoc["MBNProfile"]["Name"].InnerText;

                                        if (xdoc["MBNProfile"]["ConnectionMode"].InnerText != "auto")
                                        {
                                            xdoc["MBNProfile"]["ConnectionMode"].InnerText = "auto";
                                            updateRequired = true;
                                        }

                                        // Check the APN settings
                                        if (xdoc["MBNProfile"]["Context"] == null)
                                        {
                                            XmlElement context = (XmlElement)xdoc["MBNProfile"].AppendChild(xdoc.CreateElement("Context", xdoc["MBNProfile"].NamespaceURI));
                                            context.AppendChild(xdoc.CreateElement("AccessString", xdoc["MBNProfile"].NamespaceURI));
                                            context.AppendChild(xdoc.CreateElement("Compression", xdoc["MBNProfile"].NamespaceURI));
                                            context.AppendChild(xdoc.CreateElement("AuthProtocol", xdoc["MBNProfile"].NamespaceURI));
                                            updateRequired = true;
                                        }

                                        if (xdoc["MBNProfile"]["Context"]["AccessString"].InnerText != APNAccessString)
                                        {
                                            xdoc["MBNProfile"]["Context"]["AccessString"].InnerText = APNAccessString;
                                            updateRequired = true;
                                        }
                                        if (xdoc["MBNProfile"]["Context"]["Compression"].InnerText != APNCompression)
                                        {
                                            xdoc["MBNProfile"]["Context"]["Compression"].InnerText = APNCompression;
                                            updateRequired = true;
                                        }
                                        if (xdoc["MBNProfile"]["Context"]["AuthProtocol"].InnerText != APNAuthProtocol)
                                        {
                                            xdoc["MBNProfile"]["Context"]["AuthProtocol"].InnerText = APNAuthProtocol;
                                            updateRequired = true;
                                        }

                                        if (xdoc["MBNProfile"]["Context"]["UserLogonCred"] == null && !String.IsNullOrEmpty(APNUsername))
                                        {
                                            XmlElement userLogonCred = (XmlElement)xdoc["MBNProfile"]["Context"].InsertAfter(xdoc.CreateElement("UserLogonCred", xdoc["MBNProfile"].NamespaceURI), xdoc["MBNProfile"]["Context"]["AccessString"]);
                                            userLogonCred.AppendChild(xdoc.CreateElement("UserName", xdoc["MBNProfile"].NamespaceURI));
                                            userLogonCred.AppendChild(xdoc.CreateElement("Password", xdoc["MBNProfile"].NamespaceURI));
                                            updateRequired = true;
                                        }

                                        if (xdoc["MBNProfile"]["Context"]["UserLogonCred"] != null && xdoc["MBNProfile"]["Context"]["UserLogonCred"]["UserName"].InnerText != APNUsername)
                                        {
                                            xdoc["MBNProfile"]["Context"]["UserLogonCred"]["UserName"].InnerText = APNUsername;
                                            updateRequired = true;
                                        }

                                        if (xdoc["MBNProfile"]["Context"]["UserLogonCred"] != null && xdoc["MBNProfile"]["Context"]["UserLogonCred"]["Password"] == null && !String.IsNullOrEmpty(APNUsername))
                                        {
                                            xdoc["MBNProfile"]["Context"]["UserLogonCred"].AppendChild(xdoc.CreateElement("Password", xdoc["MBNProfile"].NamespaceURI));
                                        }

                                        if (xdoc["MBNProfile"]["Context"]["UserLogonCred"] != null && xdoc["MBNProfile"]["Context"]["UserLogonCred"]["Password"].InnerText != APNPassword)
                                        {
                                            xdoc["MBNProfile"]["Context"]["UserLogonCred"]["Password"].InnerText = APNPassword;
                                            updateRequired = true;
                                        }

                                        if (updateRequired)
                                        {
                                            // Update the connection profile
                                            profile.UpdateProfile(xdoc.OuterXml);
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                if (!ex.Message.Contains("Element not found"))
                                {
                                    throw ex;
                                }
                            }

                            if (!connProfileFound)
                            {
                                // Create the connection profile
                                XmlDocument xdoc = new XmlDocument();
                                xdoc.AppendChild(xdoc.CreateXmlDeclaration("1.0", "utf-8", "yes"));
                                XmlElement mbnProfile = (XmlElement)xdoc.AppendChild(xdoc.CreateElement("MBNProfile", "http://www.microsoft.com/networking/WWAN/profile/v1"));
                                mbnProfile.AppendChild(xdoc.CreateElement("Name", xdoc["MBNProfile"].NamespaceURI)).InnerText = SIMNumber;
                                mbnProfile.AppendChild(xdoc.CreateElement("IsDefault", xdoc["MBNProfile"].NamespaceURI)).InnerText = "true";
                                mbnProfile.AppendChild(xdoc.CreateElement("ProfileCreationType", xdoc["MBNProfile"].NamespaceURI)).InnerText = "DeviceProvisioned";
                                mbnProfile.AppendChild(xdoc.CreateElement("SubscriberID", xdoc["MBNProfile"].NamespaceURI)).InnerText = subInfo.SubscriberID;
                                mbnProfile.AppendChild(xdoc.CreateElement("SimIccID", xdoc["MBNProfile"].NamespaceURI)).InnerText = SIMNumber;
                                mbnProfile.AppendChild(xdoc.CreateElement("HomeProviderName", xdoc["MBNProfile"].NamespaceURI)).InnerText = SIMNumber;
                                mbnProfile.AppendChild(xdoc.CreateElement("AutoConnectOnInternet", xdoc["MBNProfile"].NamespaceURI)).InnerText = "true";
                                mbnProfile.AppendChild(xdoc.CreateElement("ConnectionMode", xdoc["MBNProfile"].NamespaceURI)).InnerText = "auto";

                                XmlElement context = (XmlElement)xdoc["MBNProfile"].AppendChild(xdoc.CreateElement("Context", xdoc["MBNProfile"].NamespaceURI));
                                context.AppendChild(xdoc.CreateElement("AccessString", xdoc["MBNProfile"].NamespaceURI));
                                XmlElement userLogonCred = (XmlElement)context.AppendChild(xdoc.CreateElement("UserLogonCred", xdoc["MBNProfile"].NamespaceURI));
                                userLogonCred.AppendChild(xdoc.CreateElement("UserName", xdoc["MBNProfile"].NamespaceURI));
                                userLogonCred.AppendChild(xdoc.CreateElement("Password", xdoc["MBNProfile"].NamespaceURI));
                                context.AppendChild(xdoc.CreateElement("Compression", xdoc["MBNProfile"].NamespaceURI));
                                context.AppendChild(xdoc.CreateElement("AuthProtocol", xdoc["MBNProfile"].NamespaceURI));

                                xdoc["MBNProfile"]["Context"]["AccessString"].InnerText = APNAccessString;
                                xdoc["MBNProfile"]["Context"]["UserLogonCred"]["UserName"].InnerText = APNUsername;
                                xdoc["MBNProfile"]["Context"]["UserLogonCred"]["Password"].InnerText = APNPassword;
                                xdoc["MBNProfile"]["Context"]["Compression"].InnerText = APNCompression;
                                xdoc["MBNProfile"]["Context"]["AuthProtocol"].InnerText = APNAuthProtocol;

                                profileName = xdoc["MBNProfile"]["Name"].InnerText;

                                mbnConnProfileMgrInterface.CreateConnectionProfile(xdoc.OuterXml); 
                            }

                            // Register the connection events
                            MbnConnectionManager connMgr = new MbnConnectionManager();
                            IConnectionPointContainer connPointContainer = connMgr as IConnectionPointContainer;

                            Guid IID_IMbnConnectionEvents = typeof(IMbnConnectionEvents).GUID;
                            IConnectionPoint connPoint;
                            connPointContainer.FindConnectionPoint(ref IID_IMbnConnectionEvents, out connPoint);

                            ConnectionEventsSink connEventsSink = new ConnectionEventsSink();
                            connPoint.Advise(connEventsSink, out cookie); if (showProgress) { MessageBox.Show("After registering events"); }

                            // Connect
                            IMbnConnection connection = mobileInterfaces[0].GetConnection();

                            if (connection != null)
                            {
                                MBN_ACTIVATION_STATE state;
                                string connectionProfileName = String.Empty;
                                connection.GetConnectionState(out state, out connectionProfileName);

                                if (state != MBN_ACTIVATION_STATE.MBN_ACTIVATION_STATE_ACTIVATED && state != MBN_ACTIVATION_STATE.MBN_ACTIVATION_STATE_ACTIVATING)
                                {
                                    if (String.IsNullOrEmpty(connectionProfileName))
                                    {
                                        connectionProfileName = profileName;
                                    }
                                    uint requestID;
                                    connection.Connect(MBN_CONNECTION_MODE.MBN_CONNECTION_MODE_PROFILE, connectionProfileName, out requestID);

                                }
                                else
                                {
                                    // Do nothing, already connected
                                }
                            }
                            else
                            {
                                MessageBox.Show("Connection not found.");
                            }
                        }
                        else
                        {
                            MessageBox.Show("mbnConnProfileMgrInterface is null.");
                        }
                    }
                    else
                    {
                        MessageBox.Show("No subscriber info found.");
                    }
                }
                else
                {
                    MessageBox.Show("No mobile interfaces found.");
                }
            }
            else
            {
                MessageBox.Show("mbnInfMgrInterface is null.");
            }
        }
        catch (Exception ex)
        {
            if (ex.Message.Contains("SIM is not inserted."))
            {
                SIMNumber = "No SIM inserted.";
            }
            MessageBox.Show("LoginForm.DataConnection ConfigureWindowsDataConnection Error " + ex.Message);
        }

【讨论】:

  • 您知道我是否可以在 Windows 10(即 LTSB 1607)下使用您的解决方案吗?
【解决方案2】:

读取连接状态

try
        {
            MbnInterfaceManager mbnInfMgr = new MbnInterfaceManager();
            IMbnInterfaceManager mbnInfMgrInterface = mbnInfMgr as IMbnInterfaceManager;
            if (mbnInfMgrInterface != null)
            {
                IMbnInterface[] mobileInterfaces = mbnInfMgrInterface.GetInterfaces() as IMbnInterface[];
                if (mobileInterfaces != null && mobileInterfaces.Length > 0)
                {
                    // Use the first interface, as there should only be one mobile data adapter
                    IMbnSignal signalDetails = mobileInterfaces[0] as IMbnSignal;

                    Int32.TryParse(signalDetails.GetSignalStrength().ToString(), out PhoneSignal);
                    PhoneSignal = Convert.ToInt32(((float)PhoneSignal / 16) * 100);

                    MBN_PROVIDER provider = mobileInterfaces[0].GetHomeProvider();
                    PhoneNetwork = provider.providerName.ToString();

                    if (String.IsNullOrEmpty(SIMNumber))
                    {
                        try
                        {
                            IMbnSubscriberInformation subInfo = mobileInterfaces[0].GetSubscriberInformation();

                            if (subInfo != null)
                            {
                                SIMNumber = subInfo.SimIccID;
                            }
                            else
                            {
                                SIMNumber = "Unable to read SIM info";
                            }
                        }
                        catch (Exception)
                        {
                            SIMNumber = "Unable to read SIM info";
                        }
                    }

                    // Check whether the connection is active
                    IMbnConnection connection = mobileInterfaces[0].GetConnection();

                    if (connection != null)
                    {
                        MBN_ACTIVATION_STATE state;
                        string profileName = String.Empty;
                        connection.GetConnectionState(out state, out profileName);

                        Connected = (state == MBN_ACTIVATION_STATE.MBN_ACTIVATION_STATE_ACTIVATED);
                    }
                    else
                    {
                        MessageBox.Show("Connection not found.");
                    }
                }
                else
                {
                    MessageBox.Show("No mobile interfaces found.");
                }
            }
            else
            {
                MessageBox.Show("mbnInfMgrInterface is null.");
            }
        }
        catch (Exception ex)
        {
            if (ex.Message.Contains("SIM is not inserted."))
            {
                SIMNumber = "No SIM inserted.";
            }
            else
            {
                MessageBox.Show("LoginForm.DataConnection GetWindowsMobileDataStatus " + ex.Message);
            }
            PhoneSignal = 0;
            PhoneNetwork = "Unknown";
        }

【讨论】:

    【解决方案3】:

    Windows 8 Desktop 中也提供移动宽带 API。

    如果您使用的是 Windows 8 Metro/RT/任何名称,则需要 these WindowsRT APIs (Windows.Connectivity.NetworkInformation 等)。

    【讨论】:

    • 我现在已经设法让 Mobile Broadband API 在 Win8 平板电脑上运行。由于某种原因,它不适用于所有 Win8 机器,我认为这是由于某些机器设置移动数据连接的有趣方式(例如 Lenovo Thinkpad Tablet 2,它有一个移动宽带调制解调器,但它被配置为在 Windows 中模拟以太网适配器,因此 Mobile Broadband API 不支持它)。
    • 即使没有回程移动连接,该以太网适配器是否有可能始终开启 IP 连接?
    • 我最后发现这与奇怪的伪以太网适配器无关。只是 SDK 在不同的移动宽带适配器上的行为略有不同。下面的代码适用于我尝试过的 4 种不同的 Win 7、Win 8 和 8.1 设备。不过感谢您的帮助!
    【解决方案4】:

    检查 SIM 卡是否已插入并工作/激活

    try
            {
                MbnInterfaceManager mbnInfMgr = new MbnInterfaceManager();
                IMbnInterfaceManager mbnInfMgrInterface = mbnInfMgr as IMbnInterfaceManager;
                if (mbnInfMgrInterface != null)
                {
                    IMbnInterface[] mobileInterfaces = mbnInfMgrInterface.GetInterfaces() as IMbnInterface[];
                    if (mobileInterfaces != null && mobileInterfaces.Length > 0)
                    {
                        try
                        {
                            MBN_READY_STATE readyState = mobileInterfaces[0].GetReadyState();
    
                            switch (readyState)
                            {
                                case MBN_READY_STATE.MBN_READY_STATE_BAD_SIM:
                                    MessageBox.Show("The SIM is invalid (PIN Unblock Key retrials have exceeded the limit).");
                                    break;
                                case MBN_READY_STATE.MBN_READY_STATE_DEVICE_BLOCKED:
                                    MessageBox.Show("The device is blocked by a PIN or password which is preventing the device from initializing and registering onto the network.");
                                    break;
                                case MBN_READY_STATE.MBN_READY_STATE_DEVICE_LOCKED:
                                    MessageBox.Show("The device is locked by a PIN or password which is preventing the device from initializing and registering onto the network.");
                                    break;
                                case MBN_READY_STATE.MBN_READY_STATE_FAILURE:
                                    MessageBox.Show("General device failure.");
                                    break;
                                case MBN_READY_STATE.MBN_READY_STATE_INITIALIZED:
                                    try
                                    {
                                        IMbnSubscriberInformation subInfo = mobileInterfaces[0].GetSubscriberInformation();
    
                                        if (subInfo != null)
                                        {
                                            SIMNumber = subInfo.SimIccID;
                                        }
                                        else
                                        {
                                            SIMNumber = "Unable to read SIM info";
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        SIMNumber = "Unable to read SIM info";
                                    }
    
                                    IMbnRegistration registration = mobileInterfaces[0] as IMbnRegistration;
                                    if (registration != null)
                                    {
                                        try
                                        {
                                            MBN_REGISTER_STATE regState = registration.GetRegisterState();
    
                                            switch (regState)
                                            {
                                                case MBN_REGISTER_STATE.MBN_REGISTER_STATE_DENIED:
                                                    // SIM Inactive
                                                    simInactive = true;
                                                    MessageBox.Show("The device was denied registration. The most likely cause of this error is an Inactive SIM.");
                                                    break;
                                                case MBN_REGISTER_STATE.MBN_REGISTER_STATE_DEREGISTERED:
                                                    // Do nothing - this is returned before the device has tried to register
                                                    break;
                                                case MBN_REGISTER_STATE.MBN_REGISTER_STATE_HOME:
                                                    // Do nothing
                                                    break;
                                                case MBN_REGISTER_STATE.MBN_REGISTER_STATE_NONE:
                                                    MessageBox.Show("The device registration state is unknown. This state may be set upon failure of registration mode change requests.");
                                                    break;
                                                case MBN_REGISTER_STATE.MBN_REGISTER_STATE_PARTNER:
                                                    // Do nothing
                                                    break;
                                                case MBN_REGISTER_STATE.MBN_REGISTER_STATE_ROAMING:
                                                    // Do nothing
                                                    break;
                                                case MBN_REGISTER_STATE.MBN_REGISTER_STATE_SEARCHING:
                                                    // Do nothing
                                                    break;
                                                default:
                                                    MessageBox.Show("GetRegisterState returned an unexpected state: " + regState.ToString());
                                                    break;
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            MessageBox.Show("GetRegisterState Error: " + ex.Message);
                                        }
                                    }
                                    break;
                                case MBN_READY_STATE.MBN_READY_STATE_NOT_ACTIVATED:
                                    MessageBox.Show("The subscription is not activated.");
                                    break;
                                case MBN_READY_STATE.MBN_READY_STATE_OFF:
                                    MessageBox.Show("The mobile broadband device stack is off.");
                                    break;
                                case MBN_READY_STATE.MBN_READY_STATE_SIM_NOT_INSERTED:
                                    MessageBox.Show("The SIM is not inserted.");
                                    break;
                                default:
                                    MessageBox.Show("GetReadyState returned an unexpected state: " + readyState.ToString());
                                    break;
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("GetReadyState Error: " + ex.Message);
                        }
                    }
                    else
                    {
                        MessageBox.Show("No mobileInterfaces found.");
                    }
                }
                else
                {
                    MessageBox.Show("mbnInfMgrInterface is null.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }
    

    【讨论】:

      【解决方案5】:

      响应连接事件(上例中注册了事件):

          public class ConnectionEventsSink : IMbnConnectionEvents
          {
              public ConnectionEventsSink() { }
      
              public void OnConnectComplete(IMbnConnection connection, uint requestID, int status)
              {
                  // Un-register the connect event - you might not want to do this, depends on your own requirements. Do do this you need the cookie uint from when the events were registered.
                  MbnConnectionManager connMgr = new MbnConnectionManager();
                  IConnectionPointContainer connPointContainer = connMgr as IConnectionPointContainer;
      
                  Guid IID_IMbnConnectionEvents = typeof(IMbnConnectionEvents).GUID;
                  IConnectionPoint connPoint;
                  connPointContainer.FindConnectionPoint(ref IID_IMbnConnectionEvents, out connPoint);
      
                  connPoint.Unadvise(cookie);
      
                  switch (status)
                  {
                      case 0:
                          MobileBroadbandTest.Connected = true;
                          MessageBox.Show("Connected");
                          break;
                      case -2141945334:
                          MessageBox.Show("There is no SIM in the device.");
                          break;
                      case -2141945328:
                          MessageBox.Show("A PIN is required for the operation to complete.");
                          break;
                      case -2141945335:
                          MessageBox.Show("The network service subscription has expired.");
                          break;
                      case -2141945337:
                          MessageBox.Show("The provider is not visible. This applies only to manual registration mode.");
                          break;
                      case -2141945340:
                          MessageBox.Show("The connection access string is not correct.");
                          break;
                      case -2141945333:
                          MessageBox.Show("An active voice call is in progress.");
                          break;
                      case -2141945339:
                          MessageBox.Show("There is already an Mobile Broadband context active. The Mobile Broadband service does not currently support multiple active contexts.");
                          break;
                      case -2141945336:
                          MessageBox.Show("The device radio is off.");
                          break;
                      case -2141945338:
                          MessageBox.Show("No active attached packet service is available.");
                          break;
                      case -2141945326:
                          MessageBox.Show("Generic Failure.");
                          break;
                      case -2141945320:
                          MessageBox.Show("Profile is invalid.");
                          break;
                      case -2141945319:
                          MessageBox.Show("Default profile exist.");
                          break;
                      case -2141945327:
                          MessageBox.Show("PIN is disabled.");
                          break;
                      case -2141945329:
                          MessageBox.Show("Pin is not supported.");
                          break;
                      case -2141945330:
                          MessageBox.Show("Providers not found.");
                          break;
                      case -2141945331:
                          MessageBox.Show("Device is not registered.");
                          break;
                      case -2141945332:
                          MessageBox.Show("Visible provider cache is invalid.");
                          break;
                      case -2141945341:
                          MessageBox.Show("Requested data class is not available.");
                          break;
                      case -2141945342:
                          MessageBox.Show("Bad SIM is inserted.");
                          break;
                      case -2141945343:
                          MessageBox.Show("Context is not activated.");
                          break;
      
                      default:
                          MessageBox.Show("Unexpected status: " + status.ToString());
                          break;
                  }
              }
      
              public void OnVoiceCallStateChange(IMbnConnection connection)
              {
                  // Do nothing
              }
      
              public void OnConnectStateChange(IMbnConnection connection)
              {
                  // Do nothing
              }
      
              public void OnDisconnectComplete(IMbnConnection connection, uint requestID, int status)
              {
                  // Do nothing
              }
      

      }

      【讨论】:

      • 其他读者请注意:这是至关重要的——否则您将不会收到连接成功/不成功的通知。另外,请确保只注册一次(通常),否则会收到很多通知。这与我们这些使用同步使用(例如)RAS 的方法非常不同。
      猜你喜欢
      • 2010-11-09
      • 1970-01-01
      • 2018-03-06
      • 2011-08-07
      • 1970-01-01
      • 1970-01-01
      • 2011-01-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多