Send notifications from a website to android push notifications

Asked

Viewed 1,013 times

-1

I created a social network, and implemented notifications on it. However, I can’t find an effective way to send site notifications (likes, comments, messages) by push notifications to the android app. I set up firebase, onesignal, and the app gets test pushs, but how do I send these notifications that are on my server, to a mobile device? I know I need Firebase for this, but how do I send server notifications to firebase? Can someone give me a light? I’ve been on this project for months and I can’t get out of the ground.

1 answer

0

On your server, basically, you need to do a post for that url (https://fcm.googleapis.com/fcm/send) with your server key inside the header Authorization and the Content-Type (for JSON is "application/json"), passing in JSON format the device token to be sent the notification and an object containing data to display the notification itself and/or another object with data that you may want to intercept in the Service that you must have implemented on Android. These parameters can be, as in the example:

{
    "to": "token_do_usuario",
    "data": {
        "chave": "algum_dado_que_voce_queira_passar"
    },
    "notification": {
        "title": "Título da notificação",
        "body": "Detalhes da notificação",
        "sound": "default"
    }
}

Remember that this is an example. You can have more details on: https://firebase.google.com/docs/cloud-messaging/server?hl=pt

Browser other questions tagged

You are not signed in. Login or sign up in order to post.