在BlackBerry中注册推送通知时超时异常

时间:2011-01-19 07:46:39

标签: blackberry

我正在尝试注册BlackBerry推送通知,但它显示超时异常。

这是我写的代码

 HttpConnection httpConn = (HttpConnection)Connector.open(url+;interface=wifi,Connector.READ, false); 

/**
 * Attempts to register this device with the BlackBerry Push server. This 
 * method also alerts the user whether the registration was successful 
 * or not.
 * 
 * @return True if the registration was successful, false otherwise.
 */

public boolean registerForService()
{
    if( !isRadioConnected() )
    {
        return false;
    }

    try
    {
        // Open a connection with the BB Push server and request registration
        byte[] encryptedData = connectAndRead(REGISTER_URL);

        // Open a new connection and register using the encrypted url.
        final String encryptedParam = new String(encryptedData);
        String encryptedUrl = BBP_SERVER + "/mss/PD_subReg?osversion="
        + getDeviceSoftwareVersion()+ "&model="
        + DeviceInfo.getDeviceName() + "&" + encryptedParam 
        + ";ConnectionType=mds-public;deviceside=false";

        byte[] statusCodeData = connectAndRead(encryptedUrl);
        resultCode=  new String(statusCodeData);
        // Status code sent back to the application from the BB Push server
       String statusCode = new String(statusCodeData);

        // Note: Developers should also register with the Content Provider 
        // in order to notify the server that it can push data to this 
        // device.

        // If registration succeeded then start listening to messages 
        // from the server.
        if( (statusCode.equals(StatusCode.REGISTER_SUCCESSFUL) || statusCode
                .equals(StatusCode.USER_ALREADY_SUSCRIBED)))           
        {
            _dataListener = new ListeningThread();
            _dataListener.start();

            showDialogAndWait("Registration Succeeded."+resultCode+responseCode);
            return true;
        }
        else
        {
            showDialogAndWait("Registration Failed\nStatus Code: " + statusCode+resultCode+responseCode);
            return false;
        }
    }
    catch(final Exception e )
    {
        showDialogAndWait("Registration Error\n" + e.toString()+resultCode+responseCode);
        return false;
    }
}

2 个答案:

答案 0 :(得分:-1)

您的设备是否已连接到网络?例如,您可以浏览网页吗?推送服务需要网络连接。

答案 1 :(得分:-2)

在Blackberry推送通知中做的简单事情,我通过做以下事情获得了成功

  1. 使用具有BIS计划的Blackberry设备
  2. 您的内容提供商应该可以公开访问