i was thinking were to put this, Windows or Android deployment, as it uses both but also PHP. But since the endpoint is Android maybe it is best here.
In short: when i use the gcm stack on this page http://forums.livecode.com/viewtopic.php?f=53&t=12864 then i can receive a complete notification with altered text, and sound.
When i use the script of it in my own stack then my stack stops sending data to my php scripts somehow(the return variable is empty).
So now i use a piece of it and send the info to a php script:
Code: Select all
on mouseUp
put "blabla" into tCollapsekey
put field "body" into tBody
put "true" into tPlaysound
put "blabla"into tPayload
put field "title" into tTitle
put "1" into tBadgevalue
put "collapse_key="&tCollapsekey & "&body="&tBody & "&play_sound="&tPlaysound & "&payload="&tPayload & "&title="&tTitle & "&badge_value="&tBadgevalue into tSenddata
answer tSenddata
post tSenddata to URL "http://mysitesomewhere.com/sendmultigcmflash.php"
put it into gcmResults
answer gcmResults
end mouseUp
This is the php script i use which will read all registrations in the database and send the notification, maybe someone has a clue what should be changed to get it working correctly:
Code: Select all
// blabla Multi gcm Send
<?php
// the commands below behind the // are the ones that i also tested instead of the lines that receive the POST from the lc stack
// but both the received or the preset ones below are not displayed on the android device
// isset adjustement to prevent error when empty_deze aanpassing zorgt ervoor dat je geen error krijgt bij een lege variable
// $collapse_key = isset ($_POST["collapse_key"]) ? $_POST['collapse_key'] : 'blabla';
//$body = isset ($_POST["body"]) ? $_POST['body'] : 'New message';
//$play_sound = isset ($_POST["play_sound"]) ? $_POST['play_sound'] : 'true';
//$payload = isset ($_POST["payload"]) ? $_POST['payload'] : 'blablabla';
//$title = isset ($_POST["title"]) ? $_POST['title'] : 'Message from you know who';
//$badge_value = isset ($_POST["badge_value"]) ? $_POST['badge_value'] : '1';
$collapse_key = $_POST["collapse_key"];
$body = $_POST["body"];
$play_sound = true;
$payload = $_POST["payload"];
$title = $_POST["title"];
$badge_value = $_POST["badge_value"];
echo $collapse_key, $body, $play_sound, $payload, $title, $badge_value;
if(isset($_POST['body'])){
$con = mysql_connect("localhost", "my_inlogname","My_password");
if(!$con){
die('MySQL connection failed');
}
$db = mysql_select_db("my_database");
if(!$db){
die('Database selection failed');
}
$registration_ids = array();
$sql = "SELECT * FROM gcmusers";
$result = mysql_query($sql, $con);
while($row = mysql_fetch_assoc($result)){
array_push($registration_ids, $row['gcmregid']);
}
// Set POST variables---notification was Notice 'body' => $abstract,
$url = 'https://android.googleapis.com/gcm/send';
// this part here seems not to work
//$message = array('collapse_key' => $collapse_key,
// 'data' => array('body' => $body,
//'play_sound' => $play_sound,
// 'payload' => $payload,
//'badge_value' => $badge_value),
// $fields = array(
// 'registration_ids' => $registration_ids,
// )
// );
// this seems to work.....partly
$message = array("notification" => $_POST['message']);
$fields = array(
'registration_ids' => $registration_ids,
'body' => $body,
'play_sound' => $play_sound,
'payload' => $payload,
'title' => @title,
'badge_value' => $badge_value,);
$headers = array(
'Authorization: key=my_api_key',
'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);
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
// Close connection
curl_close($ch);
echo $result;
}
?>
Hope that anyone has a clue what to do.
Thanks for any help.
Sphere.