0

我的应用程序有这个类:

  1. 新闻应用程序.java
  2. ScreenApp.java
  3. 项目.java
  4. ui/TableList.java

该应用程序从 Web 服务(.net)检索链接列表,我使用 KSoap 库(作为参考项目)。

我使用 JDE 4.5 进行开发,因为在 Eclipse 中我不能使用 ListField 类的方法“setRowHeight(index, int)”,所以我需要使用 JDE 4.5

好的,我编译应用程序(F7 键),并在模拟器中运行(F5 键)。在模拟器中,转到图标应用程序,然后尝试打开...没有任何事情发生...应用程序未打开...很奇怪...没有错误消息(ScreenApp.java 第 57 行)...但是...如果我再等几分钟...我看到错误消息(ScreenApp.java 第 57 行)...我想可能是因为应用程序尝试连接...

后来......我认为是因为模拟器中不存在互联网连接(我在模拟器顶部看到EDGE......很奇怪),我停止模拟器,打开MDS,再次运行模拟器(F5键),现在工作...列表显示正确...我可以在黑莓浏览器中打开链接。

现在...我将所有编译的文件放在同一个目录中,创建一个 ALX 文件:

  1. NewsApp.alx 并在设备上安装此应用程序,安装正常,我转到设备上的应用程序列表(8520),打开应用程序并看到连接消息(ScreenApp.java 第 57 行);我不明白为什么?在这部手机(8520)中,我与运营商建立了 EDGE 连接,WIFI 处于活动状态...我可以在任何页面(默认浏览器)中浏览...但我的应用无法从网络服务中检索信息... :(

有人帮我吗?

4

1 回答 1

0

当应用程序在设备上运行时,您需要在 url 末尾使用不同的连接参数。

例如。如果是 wifi,您需要在 URL 的末尾附加;interface=wifi" 。

详细代码为:需要根据设备网络调用getConnectionString()获取连接后缀。我希望这能解决你的问题。

/** 
   * @return connection string 
   */
  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())
      {            
          // logMessage("Device is a simulator and USE_MDS_IN_SIMULATOR is true");
          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;
  }
于 2011-09-19T12:57:00.707 回答