在Blackberry上获得活动连接

时间:2011-07-15 14:10:58

标签: blackberry

我使用下面的代码获取HTTP调用的连接参数。

它适用于我的测试手机和模拟器。但是对于某些人(可能只有9700个用户,但我无法保证),即使他们有其他正常工作的3G / wifi连接,也会导致"Failed to transmit"错误。

我做错了什么?

  private String getConnectionParameters()
  {
    String strCP = null;        

    int coverageStatus = CoverageInfo.getCoverageStatus();

    if((coverageStatus & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT)
    {
      // Carrier coverage
      String carrierUid = getCarrierBIBSUid();
      if(carrierUid == null) 
      {
        String wap2 = getWAP2ServiceRecord();

        if (wap2 != null)
        {
          // Try using WAP2
          strCP = ";deviceside=false;connectionUID="+wap2;  
        }
        else
        {
          // Has carrier coverage, but not BIBS or WAP2.  So use the carrier's TCP network
          strCP = ";deviceside=true";
        }
      }
      else 
      {
        // otherwise, use the Uid to construct a valid carrier BIBS request
        strCP = ";deviceside=false;connectionUID="+carrierUid + ";ConnectionType=mds-public";
      }
    }
    else if((coverageStatus & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS)
    {
      // MDS coverage found
      strCP = ";deviceside=false";
    }
    else if((WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) && RadioInfo.areWAFsSupported(RadioInfo.WAF_WLAN))
    {
      // Device is connected via Wifi
      strCP = ";interface=wifi";
    }
    else if(coverageStatus == CoverageInfo.COVERAGE_NONE)
    {
      // There is no available connection
      strCP = "";
    }
    else
    {
      // no other options found, assuming device
      strCP = ";deviceside=true";
    }

    return strCP;
  }

  private String getCarrierBIBSUid()
  {
    ServiceRecord[] records = ServiceBook.getSB().getRecords();

    for(int i = 0; i < records.length; i++)
    {
      if(records[i].getCid().toLowerCase().equals("ippp"))
      {
        if(records[i].getName().toLowerCase().indexOf("bibs") >= 0)
        {
          return records[i].getUid();
        }
      }
    }

    return null;
  }

  private String 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].getUid();
      }
    }

    return null;
  }

1 个答案:

答案 0 :(得分:0)

在找到Versatile Monkey connection code

之前,我的连接类遇到了同样的问题

我的问题是BIS连接,你需要循环并尝试每个连接。不确定它是载波还是CDMA与GSM的关系。