I am developing post and comment app, where one user can post some question, and any other use can answer on that post. but when any user comments on a post a user who post the question should receive notification. Suppose User (A) posted some question and User (B) answer on that. then user A should notify that somebody answers on your post and after clicking on a notification a particular post should open. Help me to sort the problem thankyou in advance :)
            Asked
            
        
        
            Active
            
        
            Viewed 2,079 times
        
    0
            
            
        - 
                    Best option for you will be to cloud functions with a database trigger. With this, whenever someone replies to a post, you can use the admin api to send a notification to the related user which you can easily get using the same admin api. – Kushan Oct 30 '17 at 09:50
1 Answers
1
            
            
        Did you try to read documentation?
All you need is to send POST request to
https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1
With message
Content-Type: application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA
{
  "message":{
    "token" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "notification" : {
      "body" : "This is an FCM notification message!",
      "title" : "FCM Message",
      }
   }
}
For sending message to exact user you can create new unique topic or write correct to parameter. For example:
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{ "data": {
    "score": "5x1",
    "time": "15:10"
  },
  "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}
 
    
    
        Andrey Danilov
        
- 6,194
- 5
- 32
- 56
- 
                    1can you explain me this code that how and where to implement this code > – Nabeel Nazir Oct 30 '17 at 10:07
- 
                    
- 
                    
- 
                    
- 
                    @NabeelNazir assuming search does not work: https://stackoverflow.com/questions/2938502/sending-post-data-in-android https://stackoverflow.com/questions/17810044/android-create-json-array-and-json-object – Andrey Danilov Oct 30 '17 at 11:37
- 
                    @NabeelNazir if you read examples probably you should write another question about http requests/json/etc – Andrey Danilov Oct 30 '17 at 11:39
- 
                    Which token need to be use for 'Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA' this ?, I use idToken which is return by firebase authtication . did not work – Chanuka Asanka May 02 '18 at 05:14
