Reputation: 2774
My question is.. ¿How can I change my GCM priority like google said? I was reading Google Developers when I saw that;
Setting the priority of a message
You have two options for assigning delivery priority to downstream messages: normal and high priority. Delivery of high and normal priority messages works like this:
High priority: GCM attempts to deliver high priority messages immediately, allowing the GCM service to wake a sleeping device when possible and open a network connection to your app server. Apps with instant messaging, chat, or voice call alerts, for example, generally need to open a network connection and make sure GCM delivers the message to the device without delay. Set high priority only if the message is time-critical and requires the user’s immediate interaction, and beware that setting your messages to high priority contributes more to battery drain compared to normal priority messages.
Normal priority: This is the default priority for message delivery. Normal priority messages won't open network connections on a sleeping device, and their delivery may be delayed to conserve battery. For less time-sensitive messages, such as notifications of new email or other data to sync, choose normal delivery priority.
In my PHP when i want to send a notificacion I call this function:
function send_notification($con,$registatoin_ids,$idDestino,$titulo, $message, $nombreOrigenNotificacion, $dia, $mes, $anio, $idCancha, $idOrigen, $esComplejo) {
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'data' =>array("idDestino" => $idDestino,"title" => $titulo,"message" => $message,"nombreOrigenNotificacion" => $nombreOrigenNotificacion,"dia" => $dia,"mes" => $mes,"anio" => $anio,"idCancha" => $idCancha,"idOrigen" => $idOrigen,"esComplejo" => $esComplejo),
'registration_ids' => $registatoin_ids
);
$headers = array(
'Authorization: key=' . apiKey,
'Content-Type: application/json'
);
$ch = curl_init();
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));
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
//echo $result;
}
// EDIT: The GCM notification is between Android Phones
So..How can I change the priority GCM message? Thanks
Upvotes: 0
Views: 1254
Reputation: 8102
You may add $priority
parameter from within your function. As described in Code Reference - add_action function
$priority
Used to specify the order in which the functions associated with a particular action are executed. Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
Default value: 10
Sample code found in Generate Notifications From Your Web App With the Pushover API is shown below:
// send notification to admin mobile device via pushover
public function notify($device,$title='',$message='',$url='',$urlTitle='',$priority=1,$sound='gamelan',$debug=false) {
if ($device['send_email']<>Device::SEND_EMAIL) {
// load pushover key from Settings
$setting = Setting::model()->getSettings();
$po = new Pushover();
$po->setToken($setting['pushover_app_api_token']);
$po->setUser($device['pushover_user_key']);
$po->setDevice($device['pushover_device']);
$po->setSound($sound);
$po->setTitle($title);
$po->setMessage($message);
if ($url<>'') {
$po->setUrl($url);
}
if ($urlTitle<>'') {
$po->setUrlTitle($urlTitle);
}
$po->setPriority($priority);
$po->setTimestamp(time());
$po->setDebug(true);
$go = $po->send();
if ($debug) {
echo '<pre>';
print_r($go);
echo '</pre>';
}
}
Upvotes: 0