【问题标题】:app works in simulator but not in device应用程序可以在模拟器中运行,但不能在设备中运行
【发布时间】:2011-09-17 17:29:32
【问题描述】:

我的应用程序有这些课程:

  1. NewsApp.java
  2. ScreenApp.java
  3. Item.java
  4. ui/TableList.java

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

我使用 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 处于活动状态......我可以在任何页面(默认浏览器)中浏览......但我的应用无法从网络服务中检索信息...... :(李>

有人帮帮我吗?

【问题讨论】:

  • 抛出的异常类型以及异常中包含的任何消息都可能有助于告诉我们出了什么问题。根据您使用模拟器的经验,我预计它与您使用的连接方法有关。
  • 还有......我该如何解决这个问题:S?解决这个问题的方法是什么?我需要使用什么方法?因为在示例中我需要在 try catch 中添加调用方法
  • 在您的 catch 子句(ScreenApp.java 第 57 行)中包含输出中异常的内容和类型,在此处报告。 e.toString() 会起作用。获得一本关于 Java 编程的好书也可能会有所帮助。

标签: java blackberry ksoap


【解决方案1】:

应用在设备上运行时,需要在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;
  }

【讨论】:

  • 您好,感谢您的回复,我已经使用 HttpConnectionFactory 完成了这一步...设备上的应用程序可以使用,但只能使用 WIFI,如果我尝试使用 EDGE 连接不起作用...和当我尝试导航(默认浏览器)到 asmx URL 并且我无法显示任何内容时...我看到连接超时错误...可能是因为这个原因...当我尝试从我的应用程序调用此 Web 服务时不起作用...该应用程序仅适用于 WIFI...我也需要与 EDGE 和 3G 一起使用
  • 你可以试试上面的代码作为示例应用程序,也许这对你有帮助。
猜你喜欢
  • 2015-07-31
  • 1970-01-01
  • 1970-01-01
  • 2014-03-27
  • 1970-01-01
  • 2010-10-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多