0

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!

Grant
  • 4,413
  • 18
  • 56
  • 82
  • 1
    *Normally*, you would specify the APN settings by navigating into the BlackBerry device settings (Options -> Advanced Options -> TCP/IP) and configuring them for the mobile carrier you use. Did you buy an unlocked phone, and not setup the APN settings already? – Nate May 31 '13 at 08:01
  • possible duplicate of [APN is not specified?](http://stackoverflow.com/questions/5620594/apn-is-not-specified) – Nate May 31 '13 at 08:03
  • Also, if you do happen to want to configure APN settings dynamically in code, [here's a link on that](http://supportforums.blackberry.com/t5/Java-Development/Specify-APN-information-for-a-direct-TCP-connection/ta-p/445860). – Nate Jun 01 '13 at 04:39
  • Yes that was the error. After setting APN settings I was successful Thanks Nate. – Grant Jun 01 '13 at 09:10

0 Answers0