Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

BlackBerry Push Development

Reply
New Contributor
felhabbal
Posts: 6
Registered: ‎03-19-2013
My Device: Blackberry Z10

Empty Push notification

Hi All,

 

Here is what I have so far ---  I ported an android app to Blackberry -  followed all the necessary instructions etc.

 

The app registers with blackberry server and I get the device PIN (ID)

 

Now my php initiator works properly and send a message to the specific Device but the message is empty, it has the title name of  the App and the body has the date and time the notification was received...

 

The initiator is written in PHP..

Please see below...

 

<?php

// APP ID provided by RIM
$appid = 'xxxx-xxxxxxxxxxxxxxxxxxxxxx';
// Password provided by RIM
$password = 'xxxxxx';

//Deliver before timestamp
$deliverbefore = gmdate('Y-m-d\TH:i:s\Z', strtotime('+5 minutes'));

//An array of address must be in PIN format or "push_all"
$addresstosendto[] = 'xxxxxxxx';

$addresses = '';

foreach ($addresstosendto as $value) {
    $addresses .= '<address address-value="'.$value.'"/>';
}

// create a new cURL resource
$err = false;
$ch = curl_init();
$messageid = microtime(true);
$message = "Hello World";
$data = '--mPsbVQo0a68eIL3OAxnm'. "\r\n" .
'Content-Type: application/xml; charset=UTF-8' . "\r\n\r\n" .
'<?xml version="1.0"?>
<!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 2.1//EN" "http://www.openmobilealliance.org/tech/DTD/pap_2.1.dtd">
<pap>

<push-message push-id="' . $messageid . '" deliver-before-timestamp="' . $deliverbefore . '" source-reference="' . $appid . '">'
. $addresses .
'<quality-of-service delivery-method="unconfirmed"/>
</push-message>
</pap>' . "\r\n" .
'--mPsbVQo0a68eIL3OAxnm' . "\r\n" .
'Content-Type: text/plain' . "\r\n" .
'Push-Message-ID: ' . $messageid . "\r\n\r\n" .
stripslashes("Hello World") . "\r\n" .
'--mPsbVQo0a68eIL3OAxnm--' . "\n\r";

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "https://cp361.pushapi.eval.blackberry.com/mss/PD_pushRequest");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_USERAGENT, "Hallgren Networks BB Push Server/1.0");
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $appid . ':' . $password);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/related; boundary=mPsbVQo0a68eIL3OAxnm; type=application/xml", "Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2", "Connection: keep-alive"));

// grab URL and pass it to the browser
$xmldata = curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);

//Start parsing response into XML data that we can read and output
$p = xml_parser_create();
xml_parse_into_struct($p, $xmldata, $vals);
$errorcode = xml_get_error_code($p);
if ($errorcode > 0) {
    echo xml_error_string($errorcode);
    $err = true;
}
xml_parser_free($p);

echo 'Our PUSH-ID: ' . $messageid . "<br \>\n";
if (!$err && $vals[1]['tag'] == 'PUSH-RESPONSE') {
    echo 'PUSH-ID: ' . $vals[1]['attributes']['PUSH-ID'] . "<br \>\n";
    echo 'REPLY-TIME: ' . $vals[1]['attributes']['REPLY-TIME'] . "<br \>\n";
    echo 'Response CODE: ' . $vals[2]['attributes']['CODE'] . "<br \>\n";
    echo 'Response DESC: ' . $vals[2]['attributes']['DESC'] . "<br \> \n";
} else {
    echo '<p>An error has occured</p>' . "\n";
    echo 'Error CODE: ' . $vals[1]['attributes']['CODE'] . "<br \>\n";
    echo 'Error DESC: ' . $vals[1]['attributes']['DESC'] . "<br \>\n";
}

?>

Please help? 

Please use plain text.
Retired
marco_dicesare
Posts: 76
Registered: ‎08-08-2012
My Device: BlackBerry Z10

Re: Empty Push notification

I am not sure I fully understand what issue you are having.

 

What does the JSON data you are pushing look like?

 

 

If your JSON data looks like this, for example:

{
   "data":{
      "for":"bar"   
   }
}

Then you would obtain it by issuing:
intent.getExtra("data"); 


Or if your JSON data looks like this, for example:

{
   "foo":"bar"   
}

Then you would obtain it by issuing:
intent.getExtra("foo"); 

 

Please use plain text.
New Contributor
felhabbal
Posts: 6
Registered: ‎03-19-2013
My Device: Blackberry Z10

Re: Empty Push notification

my app does this

String message = intent.getExtras().getString("msg");

 

So the feed is "msg": "text of the message"

 

But what I am saying is that the code above,, is a push initiator,, it sends out a notification to the physical device....

so the code works... but when you open the push notification on BB10 phone,, the only text you see in the body of the message is the date and time the message was delivered.. you don't see anything else..

 

What's causing that?

 

Thanks again for your help...

 

Please use plain text.
Retired
mdandrea
Posts: 311
Registered: ‎08-08-2012
My Device: BlackBerry Z10

Re: Empty Push notification

[ Edited ]

Have you read this web page?

http://developer.blackberry.com/android/apisupport/creating_push-enabled_android_apps.html

 

You need to send your content in JSON format.

 

It looks like you're just sending "Hello World" as the content from your Push Initiator code you posted.

 

Try something like:

 

{ "msg":"Hello World" }

Matt

Please use plain text.
New Contributor
felhabbal
Posts: 6
Registered: ‎03-19-2013
My Device: Blackberry Z10

Re: Empty Push notification

Ok,,

 

OK,, so where in this code I put my json feed?

 

where does this peice of code go??

 

 

Please use plain text.
Retired
marco_dicesare
Posts: 76
Registered: ‎08-08-2012
My Device: BlackBerry Z10

Re: Empty Push notification

Replace this "Hello World":

 

stripslashes("Hello World") . "\r\n" .

 

with:

{
  "msg":"Hello World"
}

 Then in your app use the intent to get msg from the extras

Please use plain text.
New Contributor
felhabbal
Posts: 6
Registered: ‎03-19-2013
My Device: Blackberry Z10

Re: Empty Push notification

I replaced it with this.. and it works,,, thanks again

 

'{ "msg":"Hello World"}' . "\r\n\r\n" .

 

Please use plain text.