I am doing my first steps in Django-Android interaction, and I am bit confused about the logic how FCM technology works. I have installed django-fcm via pip, and now my goal is to send a notification to Android device via FCM token that has been sent to server by Android device via REST resource.
The third-party Android developers tell that they would give me only the FCM token and I should be able to send a notification. And I'm a bit confused by the following code snippet from the doc
devices = FCMDevice.objects.all()
What is FCM device ? And how does JSON code in the example:
{
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark",
"icon" : "myicon"
}
}
...related to this:
device = FCMDevice.objects.all().first()
device.send_message("Title", "Message")
device.send_message(data={"test": "test"})
device.send_message(title="Title", body="Message", icon=..., data={"test": "test"})
THE QUESTION IS what is the minimum code snippet to send the simplest notification to an Android device identified by its FCM token
FCM also has a Console where you can send the Message/Notification from, without having your own app server. NOTE: Creating your own app server is up to you. Just stating that you can send a message/notification via the console. The URL used is "https://android.googleapis.com/gcm/send".
Django-Webpush is a package that enables developers to integrate and send web push notifications in Django applications.
Firebase Cloud Messaging(FCM), was formerly known as Google Cloud Messaging(GCM). FCM is a cloud platform that provides messages and push notifications for operating systems- ios and Android, and websites as well.
To send a notification via your django app server, you need to:
'fcm_django'
to your INSTALLED_APPS
.FCM_APIKEY = <your_api_key>
device_instance.send_message
(notification = { "body" : "great match!",
"title" : "Portugal vs. Denmark",
"icon" : "myicon"})
To fully understand how django-fcm works, I would advice that you actually go through the source code. If an open source package is disturbing me, actually viewing the source code and reading the comments is sometimes enlightening. django-fcm is a small and simple package. The utils.py file is the most important. That is where the message is composed and sent to Firebase using the python's requests package. To understand this file. Please also read the docs for firebase at: https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-json
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With