我想在通过Google通知发送到应用程序的远程通知中添加一个图像。
我通过PHP将通知发送到Google。这本身似乎与我找到的文档不太匹配,它告诉我要发送一个“message”参数,而实际上在应用程序上显示的是“警告”。
下面是我的PHP代码:
public function send_notification($registation_ids, $message) {
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
echo 'Message: '.$message.'<br>';
$fields = array(
'registration_ids' => $registation_ids,
'data' => array(
'message' => $message,
'alert' => $message
)
);
$headers = array(
'Authorization: key=' . GOOGLE_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) {
return curl_error($ch);
}
// Close connection
curl_close($ch);
return $result;
}我会想,我只需要发送一个图标连同有效载荷,但我找不到任何文档来支持这一点。
另一种选择是将图标放在应用程序本身上,然后调用有效载荷中的一个变量来引用该图标,但也找不到任何文档来支持该图标。
顺便提一句,这个应用程序是使用Corona构建的,但我不确定这有多重要。
任何帮助都将不胜感激。谢谢
发布于 2014-03-13 10:25:07
据了解,Corona在项目的根中寻找特定的文件名,并使用该文件名。有3种文件的名称格式,每一个有几个版本为不同的新闻部。据我所知,目前您不能根据警报的有效负载更改此图标。
白色,用于Android 3.0+
IconNotificationDefault-ldpi-v11.png
IconNotificationDefault-mdpi-v11.png
IconNotificationDefault-hdpi-v11.png
IconNotificationDefault-xhdpi-v11.png 灰色,适用于Android 2.3-3.0
IconNotificationDefault-ldpi-v9.png
IconNotificationDefault-mdpi-v9.png
IconNotificationDefault-hdpi-v9.png
IconNotificationDefault-xhdpi-v9.png黑色的,为了其他一切
IconNotificationDefault-ldpi.png
IconNotificationDefault-mdpi.png
IconNotificationDefault-hdpi.png
IconNotificationDefault-xhdpi.png发布于 2014-03-05 15:32:20
您可以从服务器发送任何您想要的数据,只要您不发送超过4K的数据。至于您应该发送message还是alert,这完全取决于客户端的代码,因为这是查找这些参数并使用它们的值的代码。
要将图标直接与有效负载一起发送,您必须将图像编码为字符串,并将该字符串包含在有效负载中(假设它是一个足够小的图像)。您的应用程序将必须解码该字符串,以显示图标。您的另一个选项,发送一个对图标的引用,更有意义。同样,必须处理该引用的是客户机(应用程序)代码。
https://stackoverflow.com/questions/22197241
复制相似问题