0

我使用了以下类,它扩展了 Thread 以连接到网络

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;
}
}

但如您所见,该 URL 绑定到一个 wifi 接口。看以下几行。

private String myinterface = ";interface=wifi";
conn = (HttpConnection) Connector.open(this.url + this.myinterface, Connector.READ);

我想通过移动服务提供商直接将设备连接到互联网,而不使用 wifi 接口。如果可以的话,是否可以删除this.myinterface,请告诉我该怎么做

我已删除绑定到接口并在设备上对其进行了测试。但它弹出一个错误说

java.io.IOException: APN is not specified

我需要在我的代码中指定 APN 吗?

谢谢!

4

0 回答 0