Sending push notifications in android after regular intervals using Firebase cloud messaging

I am making an android app where I am using firebase authentication for authenticating users and firestore for storing some user data. I want to allow users to have a setting where they can subscribe to push notifications. If they subscribe, I want my app to send them notifications at regular intervals, say once every 6 hours. For now, I have tested the push notifications using the firebase console and it seems to work fine. Here is my file so far:

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    public void onNewToken(@NonNull String token) {

    public void sendRegistrationToServer(String token) {
        UserApi.getInstance().setToken(token);// send the token to firestore


Now, I want to send a notification using FireBase Cloud Messaging. I am not able to understand how to achieve this. I tried searching a lot but the only way I can find is through using node.js and cloud functions. But how do I achieve this ? My user document has a attribute which is set to true for users who have subscribed to notifications. What would be the typescript code to automate the notification process for them? I am using Firebase for the first time.

EDIT 1: Also, when now I think about it, I think that I don’t need the device token for achieving this maybe

EDIT 2: After looking at the comments by Frank, I am using this curl command to test if the push notifications are working for subscribed users

curl -X POST -H "Authorization: Bearer APP_SERVER_KEY" -H "Content-Type: application/json" -d '{
  "message": {
    "topic" : "notifications",
    "notification": {
      "body": "This is a Firebase Cloud Messaging Topic Message!",
      "title": "FCM Message"
}' HTTP/1.1

For some reason, the above command doesn’t work in powershell and gives the following erros:

curl: (6) Could not resolve host: is
curl: (6) Could not resolve host: a
curl: (6) Could not resolve host: Firebase
curl: (6) Could not resolve host: Cloud
curl: (6) Could not resolve host: Messaging
curl: (6) Could not resolve host: Topic
curl: (3) Illegal characters found in URL
curl: (3) [globbing] unmatched close brace/bracket in column 13
  "error": {
    "code": 401,
    "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See",
    "status": "UNAUTHENTICATED"
curl: (6) Could not resolve host: HTTP

I am losing my hair thinking about what is wrong with this and why is it so hard ? I have gone over many SO links but none seem to solve my problem. After this works, I still need to schedule notifications which might be even harder? :/


To send messages through Firebase Cloud Messaging, you need to call its API and specify the FCM server key. As its name implies, this key should only be used on servers – or otherwise trusted environments, such as your development machine or Cloud Functions. For more on this, see How to send one to one message using Firebase Messaging.

Once you have code calling the FCM API, you’ll need to target the right devices. There are two main options for that, either you know the device’s token and you target the individual device, or you have the device subscribe to a so-called topic and then send the message to that topic too. For more on this, see: How do you send a Firebase Notification to all devices via CURL?

If you want to schedule the sending of the messages, you’ll need a place where you can run code on a schedule. You can do this on your own development machine, or on a server you control, but it is also possible in Cloud Functions. For more on this, see How can scheduled Firebase Cloud Messaging notifications be made outside of the Firebase Console?