应用程序在模拟器中工作,但不在设备中

时间:2011-09-17 17:29:32

标签: java blackberry ksoap

我的应用程序有这个类:

  1. NewsApp.java
  2. ScreenApp.java
  3. Item.java
  4. ui/TableList.java
  5. 应用程序从Web服务(.net)检索链接列表,我使用KSoap Library(作为参考项目)。

    我使用JDE 4.5进行开发,因为使用Eclipse我无法使用ListField类的方法“setRowHeight(index,int)”,那么我需要使用JDE 4.5

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

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

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

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

1 个答案:

答案 0 :(得分:0)

当应用程序在设备上运行时,您需要在URL的末尾使用Different connection参数。

对于前。如果是wifi,您需要在网址末尾添加; interface = wifi“

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

/** 
   * @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;
  }