BlackBerry Android Push Message Server

时间:2013-03-13 15:29:41

标签: android push-notification blackberry-10 blackberry-android

尝试推送Z10的通知时遇到问题。设备成功注册推送通知,我收到BlackBerry生成的注册ID,如"Creating Push-Enabled Android Apps"中所述。

我在尝试向该服务器发送通知时遇到问题。

对于常规Android,我使用的是GCM server library。 我必须对其进行修改,以便将消息发送到BlackBerry服务器,即https://cpXXX.pushapi.eval.blackberry.com,其中XXX是我的CPID(内容提供商ID)。

问题在于我得到了404作为回报并且不知道是什么造成了......任何想法?相同的消息会成功发送到常规Android设备...

或者,是否有人成功向您的设备发送推送消息,如果有,您可以分享请求的外观吗?

2 个答案:

答案 0 :(得分:2)

最后,我能够发出推送请求。您必须将其推送至BlackBerry服务器。我使用了BB SDK here。您必须使用的URL应如下所示:

https://cpXXX.pushapi.eval.blackberry.com/mss/PD_pushRequest

示例代码:

IdGenerator idGenerator = new IdGeneratorImpl();

        List<String> addresses = new ArrayList<String>();

        JSONObject message = new JSONObject();
        //populate message with key-value pairs
        String data = message.toString();
        //populate addresses with device PINs

        PushMessageControl pushMessageControl = new PushMessageControl(PPGType.PUBLIC_PUSH, idGenerator, "[ YOUR BlackBerryAppId]", addresses);

        Content content = new TextContent(data, "UTF-8");

        PapService papService = new PapServiceImpl();

        PushSDKProperties properties = new PushSDKPropertiesImpl();
        properties.setPublicPpgAddress("[YOUR BLACKBERRY PPG ADDRESS]");
        properties.setParserSpecialCharacters(BLACKBERRY_PARSER_SPECIAL_CHARACTERS);
        properties.setHttpIsPersistent(false);
        properties.setHttpConnectionTimeout(BLACKBERRY_CONNECTION_TIMEOUT);
        properties.setDtdDeclarationPublic(BLACKBERRY_DTD_DECLARATION_PUBLIC);
        properties.setHttpReadTimeout(BLACKBERRY_READ_TIMEOUT);

        HttpClientImpl client = new HttpClientImpl();
        client.setPushSDKProperties(properties);
        papService.setHttpClient(client);
        papService.setPushSDKProperties(properties);

        PushResponse response = papService.push("[ YOUR BlackBerryAppId]", "[ YOUR BlackBerryPassword]", "[ YOUR BlackBerryAppId]", pushMessageControl, content);

,其中

private static final int BLACKBERRY_READ_TIMEOUT = 120000;

private static final int BLACKBERRY_CONNECTION_TIMEOUT = 60000;

private static final char[] BLACKBERRY_PARSER_SPECIAL_CHARACTERS = new char[] {'&', '"', ':', '<'};

private static final String BLACKBERRY_DTD_DECLARATION_PUBLIC = "<!DOCTYPE pap PUBLIC \"-//WAPFORUM//DTD PAP 2.1//EN\" \"http://www.openmobilealliance.org/tech/DTD/pap_2.1.dtd\">";

答案 1 :(得分:0)

根据您的要求,您添加了许多内容:

  1. 您必须为此网址https://android.googleapis.com/gcm/send创建请求。
  2. 您必须在服务器API密钥的标头中添加。
  3. 并且您还必须添加到您的请求标题中,Google API控制台为您提供了2和3的发件人ID。
  4. 最后,这是我用来推送5000及更多用户的通知的代码:
  5. 注意:它是由ASP.Net和VB.Net开发的,但所有必须采用相同的原则:

    Dim request As WebRequest = WebRequest.Create("https://android.googleapis.com/gcm/send")
    request.Method = "POST"
    request.ContentType = "application/json"
    request.Headers.Add("Authorization: key=AIzaSyA47-XMaePL1mmI0P1yQ9V4sntMVn9q-1o")
    request.Headers.Add("Sender: id=648406549877")
    Dim collapsKey = Guid.NewGuid.ToString("n")
    Dim postdata As String = "{""registration_ids"":" + ids(j) + ",""data"":{""message"":""" + TextBox1.Text + """,}" + ",""collapse_key"":""" + collapsKey + """,}"
    Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postdata)
    request.ContentLength = byteArray.Length
    Dim dataStream As Stream = request.GetRequestStream
    dataStream.Write(byteArray, 0, byteArray.Length)
    dataStream.Close()
    Dim resposne As WebResponse = request.GetResponse
    Dim dataresponse As Stream = resposne.GetResponseStream
    Dim reader As New StreamReader(dataresponse)
    Dim sResponseFromServer As String = reader.ReadToEnd
    reader.Close()