0

I am sending a Notification from my server (Django) using django-push-notifications through FCM:

from push_notifications.models import GCMDevice
agents_user_ids = [agent.user.id for agent in task.agents.all()]
devices = GCMDevice.objects.filter(user_id__in=agents_user_ids)
devices.send_message("You have a new task", title="New Task")

I am able to receive the data in a mobile app (ionic 1.3.3, angularjs 1.5.3) using cordova-plugin-fcm:

FCMPlugin.onNotification((data) => {
        alert(JSON.stringify(data));
    }, function(msg){
        console.log("FCM Notification callback registered.");
    }, function(err){
        console.log("FCM Notification callback registration error: " + err);
    });

The problem is no notification is displayed in the bar, no vibration, no sound, ... I already modified the devices.send_message options using extra argument but nothing happens.

Following FCM documentation I modified manifest by adding:

<application>
    ...
    <service android:name="com.gae.scaffolder.plugin.MyFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>
    <service android:name="com.gae.scaffolder.plugin.MyFirebaseInstanceIDService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
    </service>
    <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/ic_stat_ic_notification" />
    <meta-data android:name="com.google.firebase.messaging.default_notification_color" android:resource="@color/colorAccent" />
</application>

Is it a problem with app configuration? with the way I send the notification from server? or it is just the plugins I am using don't display anything in the notifications bar?

... Shall I create the notification manually using the received data?

juankysmith
  • 11,839
  • 5
  • 37
  • 62

1 Answers1

1

Could be two reasons

  1. Is your app in the background when receiving it? Check https://firebase.google.com/docs/cloud-messaging/android/receive

  2. Also based on the above link, only under two situations, your device will automatically show your message as a notification. The message might be delivered to your app, where your app will then need to push a notification to the device. Check https://developer.android.com/training/notify-user/build-notification.html

katie
  • 197
  • 2
  • 11
  • First at all, I am trying to make it work with the app in foreground. Following your links, I included the meta data in the application tag of my Manifest with no results :( – juankysmith Apr 07 '17 at 06:55
  • @juankysmith as mentioned in the first link, when your app is in foreground, message will be passed directly to your onMessageReceived() method in your class extending FirebaseMessagingService. You have process the message, and build a notification in your own code using the second link. In other words, when using FCM and app is foreground, NO notification will automatically show. You have to code it. – katie Apr 07 '17 at 16:11