Page 1 of 1

Sending push notification from outside Appery Services

Posted: Sun Apr 12, 2015 2:45 pm
by Voltaire

Hello, I am sending a push notification message to my app through another server without using the Appery Push services, am using a php script with google api cloud service, am getting the push notification sound with the default icon, I know how to change the push notification icon but the problem is that am getting empty message !!! i am using the following script:

public function googlePush($DeviceID, $Message)
{
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';

$DeviceID = array($DeviceID);
$Message = array("MSG" = $Message, "MSGCNT" = $Message, "message" = $Message,"sound"="beep.wav");

$fields = array(
'registration_ids' = $DeviceID,
'data' = $Message,
);

$headers = array(
'Authorization: key=' . 'XXXXXX_MY_API_KEYXXXXXXXXXXXX',
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();

// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

// Execute post
$result = curl_exec($ch);
if ($result === FALSE) {
echo 'Curl failed: '.curl_error($ch);
}else{
echo $result;

}
// Close connection
curl_close($ch);
//echo $result;

return;
}

What are the attributes to be used so that the push notification shows the message content.
Thanks in advance


Sending push notification from outside Appery Services

Posted: Sun Apr 12, 2015 3:45 pm
by Illya Stepanov

Hi Voltaire -

You will need to clarify this within Google API Cloud service documentation and their support.

We are using JavaScript Push notification API in our apps: https://devcenter.appery.io/documenta...


Sending push notification from outside Appery Services

Posted: Sun Apr 12, 2015 4:07 pm
by Voltaire

I understand, still are you using phonegap notification plugin or any other plugin because the payload data changes from one plugin to another. the script I did provide is working fine on another application which I built on phonegap and eclipse.
Please advise


Sending push notification from outside Appery Services

Posted: Sun Apr 12, 2015 4:16 pm
by Illya Stepanov

Yes, please take a look here: https://devcenter.appery.io/documenta...


Sending push notification from outside Appery Services

Posted: Sun Apr 12, 2015 11:32 pm
by Voltaire

All you had to do is to tell me to replace the string "message" with "alert" !!!!
Thanks anyway I figured out from an old post.
Regards;


Sending push notification from outside Appery Services

Posted: Sun Apr 12, 2015 11:51 pm
by Voltaire

Still another thing, I realized that when the app is active if you receive a push notification it does not reveal directly, the phone play a sound and you have to go to the notification list to read the message, is there a way to launch the received message like an alert in java when the app is active ?


Sending push notification from outside Appery Services

Posted: Wed Apr 15, 2015 9:18 am
by Serhii Kulibaba

Hello,

Use JS code to show this message, e.g.:
prealert (data.aps.alert);/pre

More info here:
https://devcenter.appery.io/tutorials...


Sending push notification from outside Appery Services

Posted: Wed Apr 15, 2015 9:34 am
by Voltaire

Thanks a lot.