Specify the PDE server information

Before you begin:

You must have the user ID, password, IP address and port number that the wireless service provider uses for their PDE server.

  1. Import the required classes.
    import net.rim.device.api.gps.*;
    import javax.microedition.location.*;
  2. Create a class and a constructor.
    public class handleGPS
    {
        static GPSThread gpsThread;
    
        public handleGPS()
        {
        }
    }
  3. In the constructor, create and start an instance of the Thread class.
    gpsThread = new GPSThread();
    gpsThread.start();
  4. In the class, create a private static class that extends Thread, and create a run() method.
    private static class GPSThread extends Thread
    {
       public void run()
       {
       }
    }
  5. In the run() method of the private class, invoke isGPSModeAvailable() passing GPS_MODE_ASSIST as a parameter to determine if the assisted mode is available on the BlackBerry® device. Invoke isPDEInfoRequired() to determine if you need to specify PDE server information. If PDE server information is required, create an instance of the BlackBerryCriteria class by passing GPS_MODE_ASSIST as a parameter to the constructor.
    if ( !GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_ASSIST) ||
        !GPSSettings.isPDEInfoRequired(GPSInfo.GPS_MODE_ASSIST))
        return;
    
    BlackBerryCriteria myCriteria = new BlackBerryCriteria
      (GPSInfo.GPS_MODE_ASSIST);
  6. In the run() method of the private class, create a try/catch block. In the block, associate an instance of the BlackBerryCriteria class with a BlackBerryLocationProvider object. Create and specify the user ID, password, and IP address String objects, and the port ID. Combine the String objects into a single String. Invoke setPDEInfo()to specify the PDE server IP address and port number of the BlackBerry device.
    try
    {
        BlackBerryLocationProvider myProvider =
          (BlackBerryLocationProvider)
          LocationProvider.getInstance(myCriteria);
        String user = "UserID";
        String pass = "Password";
        String ip = "127.0.0.1";
        int port = 0;
        String str = ip + ";" + user + ";" + pass;
        GPSSettings.setPDEInfo(str, port);
    
        try
        {
            BlackBerryLocation myLocation =
              (BlackBerryLocation)myProvider.getLocation(10);
        }
        catch ( InterruptedException iex )
        {}
        catch ( LocationException lex )
        {}
    }
    catch ( LocationException lex )
    {}
    
    return;

Was this information helpful? Send us your comments.