【问题标题】:Check wifi condition in Blackberry application在黑莓应用程序中检查 wifi 状况
【发布时间】:2011-09-21 06:01:39
【问题描述】:

我为黑莓设备开发了一个应用程序。如果应用程序通过数据服务提供商使用互联网,则该应用程序运行良好。

我有 BB 9550,我想通过 wifi 使用我的应用程序。我尝试了很多,但我无法得到正确的答案来检查 wifi 状况。

我们如何区分为 wifi 或数据服务提供商运行我们的应用程序?

【问题讨论】:

    标签: blackberry wifi


    【解决方案1】:

    为了检查wifi是否连接,以下方法会帮助你。

     public static boolean isWifiConnected()
        {
            try
            {
                if (RadioInfo.getSignalLevel(RadioInfo.WAF_WLAN) != RadioInfo.LEVEL_NO_COVERAGE)
                {
                    return true;
                }
            }
            catch(Exception e)
            {
                System.out.println("Exception during get WiFi status");
            }
            return false;
        } 
    

    如果wifi未连接,以下方法将有助于添加数据服务。

    public static String getConnParam(){
            String connectionParameters = "";
            if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
            // Connected to a WiFi access point
            connectionParameters = ";interface=wifi";
            } else {
            int coverageStatus = CoverageInfo.getCoverageStatus();
            ServiceRecord record = getWAP2ServiceRecord();
            if (record != null
            && (coverageStatus & CoverageInfo.COVERAGE_DIRECT) ==
            CoverageInfo.COVERAGE_DIRECT) {
            // Have network coverage and a WAP 2.0 service book record
            connectionParameters = ";deviceside=true;ConnectionUID="
            + record.getUid();
            } else if ((coverageStatus & CoverageInfo.COVERAGE_MDS) ==
            CoverageInfo.COVERAGE_MDS) {
            // Have an MDS service book and network coverage
            connectionParameters = ";deviceside=false";
            } else if ((coverageStatus & CoverageInfo.COVERAGE_DIRECT) ==
            CoverageInfo.COVERAGE_DIRECT) {
            // Have network coverage but no WAP 2.0 service book record
            connectionParameters = ";deviceside=true";
            }
    
        }
            return connectionParameters;
        }
            private static  ServiceRecord getWAP2ServiceRecord() {
                ServiceBook sb = ServiceBook.getSB();
                ServiceRecord[] records = sb.getRecords();
                for(int i = 0; i < records.length; i++) {
                String cid = records[i].getCid().toLowerCase();
                String uid = records[i].getUid().toLowerCase();
    
                if (cid.indexOf("wptcp") != -1 &&
                uid.indexOf("wifi") == -1 &&
                uid.indexOf("mms") == -1) {
                return records[i];
                }
                }
                return null;
                }
    

    使用上述方法的示例。

    String connParams=(isWifiConnected())?";interface=wifi":getConnParam();
    

    希望对你有帮助

    【讨论】:

      【解决方案2】:

      试试这个:

      private static String getParameters() {
          if (GetWiFiCoverageStatus()) {
              return ";deviceside=true;interface=wifi";
          }
          else {
              return yourParametersForEdge
          }
      }
      
      private static boolean GetWiFiCoverageStatus()  {
          if((WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)) {
              return true;
          } 
          else 
              return false;           
      }
      

      当您需要连接时,您必须将参数添加到 URL:

      yourUrl = yourUrl + getParameters();
      

      【讨论】:

      • 感谢您的代码,您的代码也有助于我在 url 中添加参数
      猜你喜欢
      • 2011-09-13
      • 1970-01-01
      • 1970-01-01
      • 2016-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多