Voltaire
Posts: 0
Joined: Thu Apr 09, 2015 8:48 pm

Sending push notification from outside Appery Services

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

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Sending push notification from outside Appery Services

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...

Voltaire
Posts: 0
Joined: Thu Apr 09, 2015 8:48 pm

Sending push notification from outside Appery Services

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

Voltaire
Posts: 0
Joined: Thu Apr 09, 2015 8:48 pm

Sending push notification from outside Appery Services

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;

Voltaire
Posts: 0
Joined: Thu Apr 09, 2015 8:48 pm

Sending push notification from outside Appery Services

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 ?

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Sending push notification from outside Appery Services

Hello,

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

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

Return to “Issues”