1

I'm trying to send data-only FCM message to topic subscribers. But it not works nether when app in background or closed.

My android app have following code:

FirebaseMessaging.getInstance().subscribeToTopic("topicname");

My FCM-sender code

from pyfcm import FCMNotification

API_KEY = "AAAA....akZKg"

push_service = FCMNotification(api_key=API_KEY)

data = {
        "title":"mytitle",
        "body":"mybody",
        "url":"myurl"
        }

print(push_service.notify_topic_subscribers(topic_name="topicname", data_message=data))

outputs

{'canonical_ids': 0, 'results': [], 'failure': 0, 'success': 1, 'multicast_id': None}

But notification not appear. Need to show message to all topic subscribers that are not have running-right-now-app (have background or closed state)

amazingbasil
  • 1,695
  • 3
  • 18
  • 23
  • Check out Send a data message. https://pypi.python.org/pypi/pyfcm/ – Qamar Dec 22 '16 at 11:08
  • there is no example with sending data-only-payload messages to topic subscribers. That is the option that I need to realize – Vassily Dec 22 '16 at 11:26

1 Answers1

1

Hi Please upgrade to the latest version of pyfcm.After going through the source code i find that pyfcm always added a 'notification' dict in payload,but now they introduce a option "remove_notification" option in its source code which prevent the addition to payload. So as pyfcm does not provide any method for data only "notify_topic_subscribers" we have to override the fcm.py or fork the project and change. In fcm.py method add "remove_notification" to "notify_topic_subscribers" method and make it true in "parse_payload" call in that function.Thats it.

Sibasish
  • 346
  • 3
  • 10