php - 谷歌 FCM : badge counter restricted to iOS?

标签 php android push-notification firebase-cloud-messaging

我对 Google FCM 很困惑。 文档页面 https://firebase.google.com/docs/cloud-messaging/http-server-ref列出了 API 支持的参数,但奇怪的是,“badge”参数仅显示为“iOS”。

直到上周我都成功地设置了我的 android 应用徽章计数器,但是今天,在“通知”部分内发送参数“徽章”不起作用。通知成功到达。

我的通知数据结构:

Array
(
    [to] => (device token)
    [notification] => Array
        (
            [title] => Title
            [text] => Test message
            [sound] => default
            [vibrate] => 1
            [badge] => 2
        )
)

我的服务器端代码(PHP):

$jsonData = json_encode($data);

$ch     = curl_init("https://fcm.googleapis.com/fcm/send");
$header = array(
    'Content-Type: application/json',
    "Authorization: key=".MY_GCM_API_KEY
);

curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, true);
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);

$result = curl_exec($ch);
curl_close($ch);

最佳答案

Android 不支持应用程序图标上的徽章来表示未读通知。
(一些设备制造商添加此功能以更熟悉 iOS,但它是该设备上的自定义功能。没有标准的 Android API)

当您发送 FCM 消息时,badge 参数在 iOS 中被正确使用,但由于上述解释,它在 Android 上被简单地忽略了。

PS:这是自从在 GCM/FCM 中引入 API 以来的行为。

关于php - 谷歌 FCM : badge counter restricted to iOS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39713282/

相关文章:

push-notification - AWS Lambda 和 Google Drive 推送通知集成可能吗?

ios - 如何从服务器端清除设备上未读的推送通知?

php - 如何从远程服务器连接到 ESL?

android - ADB/Shell 命令来管理通知 channel ?

php - 如何根据使用select的输入编辑id_semester的值?

在 IntentService 中实现的 Android LocationLister 从不执行 OnLocationChanged() 方法

java - 使用 join() 方法时出现错误无法解析 'join' 中的方法 'String'

android - Firebase 推送通知在某些设备上无法正常工作

php - 什么是最常见的东西,当它们真正应该在模型中时,却被放入了 Controller ,反之亦然?

php - Rest API 404 页面未找到