【问题标题】:High priority GCM message in Android with PHP?带有PHP的Android中的高优先级GCM消息?
【发布时间】:2016-06-27 22:19:16
【问题描述】:

我的问题是.. ¿我怎样才能像谷歌所说的那样改变我的 GCM 优先级?当我看到那个时,我正在阅读 Google Developers

设置消息的优先级

您有两个选项可以为下游消息分配传递优先级:正常优先级和高优先级。高优先级和正常优先级消息的传递方式如下:

高优先级: GCM 尝试立即传递高优先级消息,允许 GCM 服务在可能的情况下唤醒睡眠设备并打开与您的应用服务器的网络连接。例如,具有即时消息、聊天或语音呼叫警报的应用程序通常需要打开网络连接并确保 GCM 将消息及时传递到设备。仅当消息时间紧迫且需要用户立即交互时才设置高优先级,并注意将消息设置为高优先级比正常优先级消息更容易消耗电池电量。

普通优先级:这是邮件传递的默认优先级。正常优先级消息不会打开睡眠设备上的网络连接,并且它们的传递可能会延迟以节省电池。对于时间敏感度较低的消息,例如新电子邮件通知或要同步的其他数据,请选择正常递送优先级。

在我的 PHP 中,当我想发送通知时,我调用了这个函数:

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;

  
}

// 编辑: GCM 通知在 Android 手机之间

那么..如何更改优先级 GCM 消息? 谢谢

【问题讨论】:

  • 对不起。但是阅读GCM 通知在Android 手机之间,它给人的印象是您正在将通知从一台Android 设备发送到另一台Android 设备。我假设这是一个错字,您是说 GCM 通知是发送到 Android 设备的?
  • @intj GCM 通知发送到 Android 设备
  • 我明白了。您是否尝试过在有效负载中添加'priority' => 'high'
  • @Intj 不,因为我不知道怎么做。函数 send_notification 在我的 php 中
  • 您是否已成功发送通知?尝试将其添加到您的 data 变量中。

标签: android json google-cloud-messaging


【解决方案1】:

您可以在函数中添加$priority 参数。如代码参考中所述 - add_action 函数

$优先级

用于指定与特定操作关联的函数的执行顺序。较低的数字对应于较早的执行,具有相同优先级的函数按照它们添加到操作的顺序执行。

默认值:10

Generate Notifications From Your Web App With the Pushover API 中的示例代码如下所示:

// 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>';      
    }      
  }

【讨论】:

  • @teyams 但我需要在我的函数中整合优先级
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-04
  • 2015-02-11
  • 2015-09-04
  • 1970-01-01
相关资源
最近更新 更多