I answered a
thread, but I actually never got it working and I like knowing what I'm talking about
So I want to receive a Notification:
I made an API key in the API manager.
I have a Server which is running this php script :
<html>
<?PHP
function SendPushNotificationAndroid( $deviceToken, $message, $title )
{
// Replace with real SERVER API key from Google APIs
$apiKey = "AIzaSyCi-XXX";
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'to' => array( $deviceToken ),
'data' => array( "message" => $message, "title" => $title ),
);
$headers = array(
'Authorization: key=' . $apiKey,
'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_POSTFIELDS, json_encode( $fields ) );
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);
echo $result;
}
if(isset($_POST['SendNotification']))
{
$Title=$_POST["Title"];
$Message=$_POST["Message"];
$DeviceToken=$_POST["DeviceToken"];
SendPushNotificationAndroid( $DeviceToken, $Message, $Title );
}
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Title: <input type="text" name="Title" value="<?php echo $Title;?>">
Message: <input type="text" name="Message" value="<?php echo $Message;?>">
Device Token: <input type="text" name="DeviceToken" value="<?php echo $DeviceToken;?>">
<input type="submit" name="SendNotification" value="Send Notification">
</form>
</html>
Then I extract the token from:
SetPushNotificationKeys( "XXXXXXXXX", "" )
result = PushNotificationSetup()
if ( result = 1 )
token$ = GetPushNotificationToken()
while ( token$ = "" )
token$ = GetPushNotificationToken()
endwhile
else
message("No Notification support")
endif
Now I try to send a notification using the token via the php script.
Do I need to publish the App via Google play or should it work with the broadcasting feature also ?