I used following class which extends the Thread to connect to the web
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import net.rim.device.api.ui.component.Dialog;
public class ConnectJson extends Thread {
private String url;
public String response;
private String myinterface = ";interface=wifi";
public void run() {
HttpConnection conn = null;
InputStream in = null;
int code;
try {
conn = (HttpConnection) Connector.open(this.url + this.myinterface, Connector.READ);
conn.setRequestMethod(HttpConnection.GET);
code = conn.getResponseCode();
if (code == HttpConnection.HTTP_OK) {
in = conn.openInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[in.available()];
int len = 0;
while (-1 != (len = in.read(buffer))) {
out.write(buffer);
}
out.flush();
this.response = new String(out.toByteArray());
if (out != null){
out.close();
}
if (in != null){
in.close();
}
if (conn != null){
conn.close();
}
}
} catch (Exception e) {
Dialog.inform(e.toString());
}
}
public String jsonResult(String url){
this.url = url;
this.start();
this.run();
return response;
}
}
but as you can see the URL is bound to a wifi interface. Look following lines.
private String myinterface = ";interface=wifi";
conn = (HttpConnection) Connector.open(this.url + this.myinterface, Connector.READ);
I want to connect the device to the internet directly via a mobile service provider without using wifi interface. Is it possible to remove this.myinterface
if it is possible please tell me how can I do that
I have removed bound to interface and tested it on the device. but it pops out an error saying that
java.io.IOException: APN is not specified
Do I need to specify APN in my code ?
Thanks!