Android Push Notifications: How do I show a title?

2019-07-15 08:31发布

问题:

We are using the Google Cloud Messaging API to push Android notifications. We are executing the https://android.googleapis.com/gcm/send endpoint with a payload similar to:

{
  "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.

回答1:

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

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

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



回答2:

Have a look at the documentation here:

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


回答3:

its working my side

$message = array("message" => $pushMessage,"title" => "My Notification");
$fields = array( "registration_ids" => "device id to send notification", "data" => $message );