简体   繁体   English

Android推送通知:如何显示标题?

[英]Android Push Notifications: How do I show a title?

We are using the Google Cloud Messaging API to push Android notifications. 我们正在使用Google Cloud Messaging API推送Android通知。 We are executing the https://android.googleapis.com/gcm/send endpoint with a payload similar to: 我们正在执行https://android.googleapis.com/gcm/send端点,其有效负载类似于:

{
  "registration_ids" : ["..."],
  "data" : {
    "message" : "You received cash back!"
  }
}

The notification works and the phone shows our app logo, and the message from above. 通知有效,手机会显示我们的应用徽标以及上面的消息。 However, there is no title in the notification (above the message and to the right of the logo): 但是,通知中没有标题(在消息上方和徽标右侧):

示例截图

For reference, we are using Phonegap 3.3 and PhoneGap Build. 作为参考,我们使用的是Phonegap 3.3和PhoneGap Build。

Well, a stab in the dark of adding "title" fixed it. 好吧,在黑暗中加入“标题”修复了它。 I wasn't able to find this documented at http://developer.android.com/google/gcm/server.html#params 我无法在http://developer.android.com/google/gcm/server.html#params上找到此文档

{
  "registration_ids" : ["..."],
  "data" : {
    "message" : "You received cash back!",
    "title" : "Title"
  }
}

Now in docs: https://developers.google.com/cloud-messaging/server#payload 现在在docs中: https//developers.google.com/cloud-messaging/server#payload

Have a look at the documentation here : 看看这里的文档:

{
  "registration_ids" : ["..."],
  "notification" : {
    "body" : "You received cash back!",
    "title" : "Title",
    "icon": "ic_notification" // replace with your own
  }
}

Edit: cloud messaging is now deprecated and this example is no longer valid. 编辑:现在不推荐使用云消息传递,此示例不再有效。 The link to the updated documentation is at firebase 更新文档的链接位于firebase

its working my side 它在我身边

$message = array("message" => $pushMessage,"title" => "My Notification"); $ message = array(“message”=> $ pushMessage,“title”=>“我的通知”);
$fields = array( "registration_ids" => " device id to send notification ", "data" => $message ); $ fields = array(“registration_ids”=>“ device id to send notification ”,“data”=> $ message);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android推送通知教程:如何将通知发送给“关注者”? - Android push notifications tutorial: how do I send notifications to “followers”? Android:如何连续显示2条通知 - Android: How do I show 2 notifications in a row 如何在Android版Corona SDK中推送通知? - How do I do push notifications in Corona SDK for Android? 当 foreground_show 设置为 false 并且我的应用程序在后台时,如何获取推送通知以显示? - How do I get push notifications to show when foreground_show is set to false and my app is in the background? 如何在Android中获取推送通知? - How can i get the push notifications in android? 我是否需要将 firebase 用于 Android 推送通知? - Do I need to use firebase for Android Push Notifications? 如何接收有关Android设备的新Outlook电子邮件的推送通知? - How do I receive push notifications of new Outlook emails to an Android device? 如何在Cordova / Phonegap Android应用程序中使用Parse.com推送通知? - How do I get Parse.com Push Notifications working in a Cordova/Phonegap Android app? 如何在 Android 中堆叠推送通知? - How to stack push notifications in Android? Android如何禁用推送通知? - Android How to disable push notifications?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM