Ahmed Wagdi
Ahmed Wagdi

Reputation: 4371

how to send data using FCM without a notification message

I am using FCM for my app, which uses Django as the back end and the front end written by flutter. I can send notifications from my Django app in certain situations and it works as expected. All I need now is to send some data to the flutter app which will behave on it somehow, but without sending a message or notification to the user.

here is how am sending notifications from my Django backend :

from pyfcm import FCMNotification
push_service = FCMNotification(api_key="****")

def send_single_notification(deviceID,title,body):
    try:
        push_service = FCMNotification(api_key="****")
        registration_id = deviceID
        message_title = title
        message_body = body
        result = push_service.notify_single_device(
        registration_id=registration_id, message_title=message_title, message_body=message_body)
    except:
        print("failed to send notification")

def send_multi_notification(list_of_ids,title,body):
    try:
        registration_ids = list_of_ids
        message_title =title
        message_body = body
        result = push_service.notify_multiple_devices(registration_ids=registration_ids, message_title=message_title, message_body=message_body)
    except:
        print("failed to send notification")


just need to send only data ..

Upvotes: 0

Views: 599

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598740

It seems like you're using pyfcm, in which case you can just send a message without a message_title and message_body as shown in this example from the documentation:

result = push_service.notify_single_device(registration_id=registration_id, data_message=data_message, content_available=True)

Upvotes: 1

Related Questions