How can I send a Firebase Cloud Messaging notification without use the Firebase Console?

后端 未结 16 1497
南旧
南旧 2020-11-22 10:17

I\'m starting with the new Google service for the notifications, Firebase Cloud Messaging.

Thanks to this code https://github.com/firebase/quickstart-a

16条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 11:02

    Use a service api.

    URL: https://fcm.googleapis.com/fcm/send

    Method Type: POST

    Headers:

    Content-Type: application/json
    Authorization: key=your api key
    

    Body/Payload:

    { "notification": {
        "title": "Your Title",
        "text": "Your Text",
         "click_action": "OPEN_ACTIVITY_1" // should match to your intent filter
      },
        "data": {
        "keyname": "any value " //you can get this data as extras in your activity and this data is optional
        },
      "to" : "to_id(firebase refreshedToken)"
    } 
    

    And with this in your app you can add below code in your activity to be called:

    
        
        
    
    

    Also check the answer on Firebase onMessageReceived not called when app in background

提交回复
热议问题