Android - abrir web desde Midlet

 
Vista:
sin imagen de perfil

abrir web desde Midlet

Publicado por Sergio (5 intervenciones) el 10/11/2015 10:31:10
Hola a todos,
por un tema laboral necesito hacer un midlet que cumpla unas determinadas funciones.
Lo que necesito es saber cómo puedo abrir una web pulsando un botón?

he mirado mucho por internet y he probado muchas cosas pero no encuentro nada en concreto que funcione.

tengo este código pero no me funciona:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class HiloConnectWWW implements Runnable {
 
	public void run() {
		try {
			String registro="";
			String[] salida;
			rs=RecordStore.openRecordStore("Almacen", true);
			RecordEnumeration enumeracion= rs.enumerateRecords (null, null, true);
 
			// Vamos recorriendo los registros con el enumerador
 
			int idregistro=enumeracion.nextRecordId();
			registro=new String(rs.getRecord(idregistro));
 
			String url = Urlwww("http://www.google.es");
 
 
		} catch (RecordStoreException ex) {
			alerta.setString("No se pudo abrir la web");
			ex.printStackTrace();
 
		}
 
	}
 
			public String Urlwww(String Url){
		HttpConnection c = null;
		InputStream is = null;
		StringBuffer sb = new StringBuffer();
		try {
			c = (HttpConnection) Connector.open(Url, Connector.READ_WRITE, true);
			c.setRequestMethod(HttpConnection.GET); //default
			is = c.openInputStream(); // transition to connected!
			int ch = 0;
			for (int ccnt = 0; ccnt < 150; ccnt++) { // get the title.
				ch = is.read();
				if (ch == -1) {
					break;
				}
				sb.append((char) ch);
			}
		} catch (IOException x) {
			x.printStackTrace();
		} finally {
			try {
				is.close();
				c.close();
			} catch (IOException x) {
				x.printStackTrace();
			}
		}
		return sb.toString();
	}
 
}

y la llamada al pulsar el botón es esta:

1
2
3
4
5
String labelwww = c.getLabel();
if (labelwww.equals("www")) {
	hiloURLwww = new Thread(new HiloConnectWWW());
	hiloURLwww.start();
}


Otra cosa que probé es este código:

1
boolean b = platformRequest("www.google.com");

pero sólo funciona en el emulador en el teléfono no funciona.


Puede alguien ayudarme por favor?

Muchas gracias.

saludoss
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder