How to send foreground and background push notification to android using django push notification package

325 Views Asked by At

Iam using django-push-notification package in django project ,

In android it the json response should be in the format :

{ "data": { "title" : "You have a notification", "body" : "The body of the notification", "id" : 1234, 
"backgroundImage" : "assets/notifications/background.png", }, 
"notification" : { "alert" : "You have a notification", "title" : "You have a notification",
"body" : "The body of the notification", "sound" : "default",
"backgroundImage" : "assets/notifications/background.png", "backgroundImageTextColour" : "#FFFFFF" } }

So that only android can get the foreground and background notifications.

I tried the code :

Views.py -

from push_notifications.models import APNSDevice, GCMDevice

try:
    fcm_device = GCMDevice.objects.all()

    fcm_device.send_message("new-notification-out",title="title-out",\
        extra={"data": { "title-data" : "title-in", "body" : "new-notification-in" }, \
        "notification" : { "alert" : "You have one new notice", "title" : "title-notify",\
         "body" : "new-notification" }})
except:
   pass

But not getting the payload "data","notification" in android side, How can I send the payload accurately from backend side ?

0

There are 0 best solutions below