java - 黑莓中所需的 radio 未激活错误

标签 java blackberry java-me wifi httpconnection

我正在尝试从黑莓代码中获取一些网络服务。这是我正在使用的代码

public void execute(int method)
    {
        HttpConnection connection = null;
        try
        {
            switch(method)
            {
                case GET:
                {
                    String combinedParams = "";
                    if(!params.isEmpty())
                    {
                        combinedParams += "?";
                        for(int i=0;i<params.size();i++)
                        {
                            String[] nameValue = SplitString.split(params.elementAt(i).toString(), ",");
                            String paramString = nameValue[0] + "=" + nameValue[1];
                            if(combinedParams.length() > 1)
                            {
                                combinedParams  +=  "&" + paramString;
                            }
                            else
                            {
                                combinedParams += paramString;
                            }
                        }
                    }
                   if(combinedParams.equals(""))
                   {
                       System.err.println("URL = "+url);
                        connection = (HttpConnection)Connector.open(url);
                   }
                   else
                   {
                       connection = (HttpConnection)Connector.open(url+combinedParams);
                   }
                   connection.setRequestMethod(HttpConnection.GET);
                   executeRequest(connection);
                   break;
                }
                case POST:
                {
                    connection = (HttpConnection)Connector.open(url);
                    connection.setRequestMethod(HttpConnection.POST);
                    for(int i=0;i<headers.size();i++)
                    {
                        String[] nameValue = SplitString.split(params.elementAt(i).toString(), ",");
                        connection.setRequestProperty(nameValue[0], nameValue[1]);
                    }
                    if(getData()!= null)
                    {
                        OutputStream os = connection.openOutputStream();
                        os.write(getData().toString().getBytes());
                        os.flush();
                    }
                    executeRequest(connection);
                    break;
                }
            }
        }
        catch(Exception e)
        {
            System.err.println(e.getMessage());
            e.printStackTrace();
        }

    }

一旦我运行这条线

connection = (HttpConnection)Connector.open(url);

我收到错误所需的 radio 未激活

我的设备中没有任何 SIM 卡,但我已连接到 WiFi,并且可以从浏览器访问其他网页。

导致此错误的可能原因是什么?

我已经尝试过这个link在我的例子中,RadioInfo.getState() 处于关闭状态

谢谢

最佳答案

来自docs在连接器上:

Wi-Fi Support

Wi-Fi connection can be established by setting the interface parameter. This only works with direct TCP/UDP connections.

interface: If the interface=wifi parameter is appended to the end of the URI string value, a Wi-Fi socket connection is opened.

这意味着您必须检测 radio 是否关闭,如果是,您可以通过在 URL 中添加 interface=wifi 来尝试使用 Wi-Fi。正确的 URL 为:http://www.google.com;interface=wifi

关于java - 黑莓中所需的 radio 未激活错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8388780/

相关文章:

java - Rest API post请求将Cucumber.json文件发送到Java中的Jira

networking - BlackBerry - 从真实设备访问网络服务

blackberry - 如何创建访问低级硬件的黑莓应用程序?

blackberry - 启动画面图像尺寸

java - 通过 JDBC 查询 Oracle DB 给出 null,而直接查询给出输出

Java哈希表搜索函数

java-me - 在诺基亚触摸设备中按下菜单按钮时调用的事件

exception - BlackBerry - 从位图创建图形对象时出现异常

java - 无法更新 TargetChangeListener

blackberry - 以编程方式拒绝 BlackBerry 上的调用