0

I made a program using OS 5.0. It works fine on emulator of a 8520 curve, and also in the device.

Now I'm trying to use this application on a 9900, with 7.0 version, and it stacks doing an HttpConnection in the device. Using my program 5.0 version, in the 9900 emulator, it works fine. Is there any difference between the 2 versions? I am putting the code that I use to make the connection in my thread. I don't know where I can find any answer to this problem.

try {
    mTimer = new Timer();
    mTimer.schedule(new CountDown(), 60000);
    UiApplication.getUiApplication().invokeLater(new Runnable() {
        public void run() {
            popup = new MyPopup("Cargando Incidentes...");
            UiApplication.getUiApplication().pushModalScreen(popup);
        }
    });

    conn = (HttpConnection) Connector.open(URL);

    InputStream contentIn = conn.openInputStream();
    byte[] data = new byte[400];
    int length = 0;
    StringBuffer raw = new StringBuffer();
    while (-1 != (length = contentIn.read(data))) {
        raw.append(new String(data, 0, length));
        str = raw.toString();
    }

    UiApplication.getUiApplication().invokeLater(new Runnable() {
        public void run() {
            try {
                conn.close();
                UiApplication.getUiApplication().invokeLater(new Runnable() {
                    public void run() {
                        try {
                            String datos[] = mainScreen.split(str, "ENDOFPAGE");
                            datos[0] = datos[0].substring(2, datos[0].length());
                            mainScreen.vecRegistro = mainScreen.split(datos[0],"$");
                            mainScreen.insertoEnBd();
                            mainScreen.insertoEnTablaDatosBD(_act);

                            UiApplication.getUiApplication().popScreen(popup);
                        } catch (Exception e) {
                            e.printStackTrace();
                            mainScreen.add(new RichTextField("Error ThreadIncidentes.run: "+ e.toString()));
                        }
                    }
                });
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
    return;
} catch (Exception e) {
}

private class CountDown extends TimerTask {
    public void run() {
        if (str.length() < 50){
            UiApplication.getUiApplication().invokeLater(new Runnable() {
                public void run() {
                    UiApplication.getUiApplication().popScreen(popup);
                    Dialog.alert("Error en la conexion");
                    System.exit(0);

                    clsThreadIncidentes.currentThread().interrupt();
                }
            });
            return;
        }
    }
}
Rupak
  • 3,674
  • 15
  • 23
Maximiliano Poggio
  • 1,162
  • 10
  • 23

1 Answers1

2

Don't use Connection.open. That is the legacy way of opening connections and usually involves a lot of code to handle suffixes depending on wheter you connect via BIS, MDS, Wi-Fi or TCP direct.

From 5.0 onwards you can use the newer Networking API. The key class to refer here is ConnectionFactory.

Mister Smith
  • 27,417
  • 21
  • 110
  • 193