Reputation: 1678
I'mm having problems when trying to push notifications for my Z10. The device successfully registers for push notifications and I receive the BlackBerry generated registration ID as described in "Creating Push-Enabled Android Apps".
I am having problems though when trying to send notifications to that server.
For regular Android I was using a GCM server library. I had to modify it so that the message is sent to BlackBerry servers i.e. https://cpXXX.pushapi.eval.blackberry.com where XXX is my CPID (Content Provider ID).
The problem is that I receive a 404 in return and don't know what's causing that... Any ideas? the same message gets sent to a regular Android device successfully...
Alternatively, did anyone succeed in sending push messages to your device and if so, could you share how the request should look like?
Upvotes: 3
Views: 1656
Reputation: 1678
Finally, I was able to make a push request. You have to push it to BlackBerry servers. I used BB SDK available here. The URL you have to use should look like this:
https://cpXXX.pushapi.eval.blackberry.com/mss/PD_pushRequest
sample code:
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);
where
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\">";
Upvotes: 2
Reputation: 2056
For your request there are many things you have add:
https://android.googleapis.com/gcm/send
.Note: it has been developed by ASP.Net and VB.Net but all must applied the same principles:
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()
Upvotes: 0