2012-03-25 7 views
1

私は自分のアプリケーションにHTTP接続を持っていますが、現時点ではユーザーがWIFI接続に接続されている場合にのみ適用されます。特定のデバイスに接続されている場合にどのように有効にしたいのですか?デバイスにBISサービス、または通常のWAPサービスがあるとします。複数の接続タイプを有効にする

これは私のコードです。

try 
    { 
     connection = (HttpConnection) Connector.open(url+ ";interface=wifi"); 
     is = connection.openInputStream(); 
     try 
     { 
      SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); 
      parser.parse(is, rssHandler); 
     } 
     catch (ParserConfigurationException e) 
     { 
      e.printStackTrace(); 
     } 
     catch (SAXException e) 
     { 
      e.printStackTrace(); 
     } 
     catch (IOException e) 
     { 
      e.printStackTrace(); 
     } 
    } 

    catch (IOException e) 
    { 
     e.printStackTrace(); 
     Dialog.inform("Bad URL"); 
    } 

答えて

3

だから、基本的に私がする必要があるすべては、上記の方法で私のhttp接続文字列を置換することである接続文字列に

/** 
* Determines what connection type to use and returns the necessary string to use it. 
* @return A string with the connection info 
*/ 
private static String getConnectionString() 
{ 
    // This code is based on the connection code developed by Mike Nelson of AccelGolf. 
    // http://blog.accelgolf.com/2009/05/22/blackberry-cross-carrier-and-cross-network-http-connection 
    String connectionString = null; 

    // Simulator behavior is controlled by the USE_MDS_IN_SIMULATOR variable. 
    if(DeviceInfo.isSimulator()) 
    { 
      if(UploaderThread.USE_MDS_IN_SIMULATOR) 
      { 
        logMessage("Device is a simulator and USE_MDS_IN_SIMULATOR is true"); 
        connectionString = ";deviceside=false"; 
      } 
      else 
      { 
        logMessage("Device is a simulator and USE_MDS_IN_SIMULATOR is false"); 
        connectionString = ";deviceside=true"; 
      } 
    } 

    // Wifi is the preferred transmission method 
    else if(WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) 
    { 
     logMessage("Device is connected via Wifi."); 
     connectionString = ";interface=wifi"; 
    } 

    // Is the carrier network the only way to connect? 
    else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT) 
    { 
     logMessage("Carrier coverage."); 

     String carrierUid = getCarrierBIBSUid(); 
     if(carrierUid == null) 
     { 
      // Has carrier coverage, but not BIBS. So use the carrier's TCP network 
      logMessage("No Uid"); 
      connectionString = ";deviceside=true"; 
     } 
     else 
     { 
      // otherwise, use the Uid to construct a valid carrier BIBS request 
      logMessage("uid is: " + carrierUid); 
      connectionString = ";deviceside=false;connectionUID="+carrierUid + ";ConnectionType=mds-public"; 
     } 
    } 

    // Check for an MDS connection instead (BlackBerry Enterprise Server) 
    else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS) 
    { 
     logMessage("MDS coverage found"); 
     connectionString = ";deviceside=false"; 
    } 

    // If there is no connection available abort to avoid bugging the user unnecssarily. 
    else if(CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE) 
    { 
     logMessage("There is no available connection."); 
    } 

    // In theory, all bases are covered so this shouldn't be reachable. 
    else 
    { 
     logMessage("no other options found, assuming device."); 
     connectionString = ";deviceside=true"; 
    } 

    return connectionString; 
} 

/** 
* Looks through the phone's service book for a carrier provided BIBS network 
* @return The uid used to connect to that network. 
*/ 
private static String getCarrierBIBSUid() 
{ 
    ServiceRecord[] records = ServiceBook.getSB().getRecords(); 
    int currentRecord; 

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

    return null; 
} 
+0

を取得するには、次のコードを使用しますか? – ocinisme

+0

はい。乾杯 – rfsk2010

関連する問題