2013-09-02 22 views
7

Đầu tiên, đây là nền tảng:C# Đọc Windows Mobile Các thuộc tính kết nối băng thông rộng

Chúng tôi có ứng dụng Windows Forms (được viết bằng C#, .NET Framework 3.5) hiện đang chạy trên máy tính bảng Windows 7 đầy đủ, có mô-đun 3G được xây dựng trong đó được sử dụng để kết nối dữ liệu. Kết nối dữ liệu được cấu hình như một kết nối băng rộng di động bình thường trong Windows (do đó Windows tự quản lý kết nối) và kết nối hiển thị trong Pa-nen điều khiển> Mạng và Internet> Kết nối mạng và kết nối hoạt động tốt - ứng dụng có thể giao tiếp qua internet với dịch vụ web của chúng tôi. Chúng tôi sẽ chuyển sang một thiết bị khác (có thể là máy tính bảng chạy Windows 8 đầy đủ) tại một thời điểm nào đó trong tương lai.

Bây giờ, những gì tôi cần làm là đọc trạng thái kết nối của kết nối Băng thông rộng di động này; tức là có được cường độ tín hiệu và tên của nhà cung cấp dịch vụ (ví dụ: Vodafone UK). Tôi đã tìm thấy cách để thực hiện việc này bằng cách sử dụng phần API băng thông rộng di động của Windows 7 SDK (xem herehere), tuy nhiên điều này dường như là hệ điều hành cụ thể vì nó không hoạt động trên Windows 8 - hoặc ít nhất là không có thiết bị tôi có ở đây.

Có cách nào chung để đọc các thuộc tính kết nối băng thông rộng di động sử dụng .NET framework không?

Ngoài ra, có ai biết SDK Windows 8 có chứa API băng rộng di động như API Windows 7 mà tôi hiện đang sử dụng không?

Xin cảm ơn trước.

Cập nhật - Tôi đã làm việc này trên một loạt các thiết bị Win 7/Win 8 khác nhau ngay bây giờ. Ngay cả các thiết bị Lenovo đang làm việc OK. Tôi sẽ đăng mã ví dụ cho các bit chính (Đọc trạng thái kết nối, định cấu hình kết nối, kiểm tra trạng thái SIM) làm câu trả lời; mã hơi quá dài để đi vào câu hỏi, khó chịu.

+1

Tôi đã thêm hầu hết các mã tôi đã kết thúc sử dụng để thử nghiệm như câu trả lời dưới đây. Mã của riêng bạn có thể sẽ không được rải rác với MessageBoxes, nhưng hy vọng những người khác sẽ tìm thấy những ví dụ hữu ích. –

+0

Xin chào, bạn làm cách nào để làm việc này trên windows 8? mbnInfMgrInterface = null, khi tôi thử tương tự trên windows 8 ... tôi có cần cài đặt bổ sung hay là Interop.MbnApi.dll đủ không? – user1841243

+2

Tất cả thiết bị Win 8 tôi đã thử quay lại với Trình quản lý IMbnInterfaceManager - mặc dù nó không hoạt động trên bất kỳ thứ gì không có bộ điều hợp băng thông rộng di động (ví dụ: máy tính để bàn của tôi). Thiết bị là gì và bộ điều hợp hoạt động khi được định cấu hình theo cách thủ công trong Windows? –

Trả lời

2

API băng thông rộng di động cũng có sẵn trong Windows 8 Desktop.

Nếu bạn đang sử dụng Windows 8 Metro/RT/tên bất kỳ, bạn cần these WindowsRT APIs (Windows.Connectivity.NetworkInformation etc).

+0

Tôi đã quản lý để có được Mobile Broadband API làm việc trên một máy tính bảng Win8 bây giờ. Nó không hoạt động trên tất cả các máy Win8 vì lý do nào đó, tôi nghĩ đó là một cách hài hước vì một số máy có thiết lập kết nối dữ liệu di động (ví dụ Lenovo Thinkpad Tablet 2, có modem băng thông rộng di động, nhưng nó được cấu hình để mô phỏng bộ điều hợp ethernet trong Windows, do đó, API băng thông rộng di động không chọn nó). –

+0

Có khả năng kết nối IP luôn bật cho bộ điều hợp ethernet này, ngay cả khi không có kết nối di động backhaul? –

+0

Tôi tìm thấy cuối cùng rằng nó không phải là bất cứ điều gì để làm với bộ chuyển đổi giả ethernet lạ. Đó chỉ là SDK hoạt động hơi khác với các bộ điều hợp băng rộng di động khác nhau. Mã dưới đây hoạt động trên 4 thiết bị Win 7, Win 8 và 8.1 khác nhau mà tôi đã thử. Cảm ơn bạn đã giúp đỡ của bạn! –

3

Đọc trạng thái kết nối:

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"; 
     } 
2

Kiểm tra SIM được lắp và làm việc/kích hoạt:

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); 
     } 
4

Cấu hình một kết nối lập trình (bạn sẽ cần các chi tiết 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); 
     } 
+0

Bạn có biết tôi có thể sử dụng giải pháp của bạn trong Windows 10 (tức là LTSB 1607) không? – creg

1

Respond to các sự kiện kết nối (sự kiện được đăng ký trong ví dụ trên):

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 
     } 

}

+0

Lưu ý cho người đọc khác: điều này là rất quan trọng - bạn sẽ không được thông báo về các kết nối đang thành công/không thành công. Ngoài ra, hãy chắc chắn để chỉ đăng ký một lần (nói chung) hoặc một được rất nhiều thông báo. Điều này là rất khác nhau trong cách tiếp cận với những người trong chúng ta sử dụng để sử dụng đồng bộ (nói) RAS. –

Các vấn đề liên quan