开发者

app works in simulator but not in device

开发者 https://www.devze.com 2023-04-05 08:36 出处:网络
I have this classes for my app: NewsApp.java ScreenApp.java Item.java ui/TableList.java The app retrieve a list of links from a webservice (.net), I use KSoap Library (as Reference project).

I have this classes for my app:

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

The app retrieve a list of links from a webservice (.net), I use KSoap Library (as Reference project).

I use JDE 4.5 for develop, because with Eclipse I cant use the method "setRowHeight(index, int)" of ListField class, then I need use JDE 4.5

Ok, I compile the app (F7 key), and run in simulator (F5 key). In simulator, go to the icon app, and try to open... nothing happends... the app not open... are strange... no error message (ScreenApp.java line 57)... but... if I few more minutes... I see the er开发者_如何学编程ror message (ScreenApp.java line 57)... I think maybe is because the app try connect...

Later... I think is because not exists a internet connection in simulator (I see EDGE in the top of simulator... is strange), I stop de simulator, open MDS, and run simulator again (F5 key), and now works... the list show correctly... and I can open the links in the blackberry browser.

Now... I put all compiled files in same directory, create a ALX file:

  1. NewsApp.alx And install this app on device, the installation works ok, I go to the list of applications on device (8520), Open the app and I see the connection message (ScreenApp.java line 57); I dont understand why ? in this phone (8520) I have EDGE connection with my carrier, I have the WIFI active... I can browse in any page (default browser)... but my app cant retrieve information from webservice... :(

Anybody help me please ?


You need to use Different connection parameter at the end of the url when application run on the device.

For ex. in case of wifi, you need to append ;interface=wifi" at the end of the URL.

Detail code is: you need to call getConnectionString() to get the connection sufix according to device network. I hope this will solve your problem.

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

精彩评论

暂无评论...
验证码 换一张
取 消