【问题标题】:Notification received but no icon displayed in notification bar收到通知但通知栏中没有显示图标
【发布时间】:2017-04-06 16:25:20
【问题描述】:

我正在使用 django-push-notifications 通过 FCM 从我的服务器 (Django) 发送通知:

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")

我可以使用cordova-plugin-fcm 在移动应用程序(ionic 1.3.3、angularjs 1.5.3)中接收数据:

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);
    });

问题是栏没有显示通知,没有振动,没有声音,...我已经使用 extra 参数修改了devices.send_message 选项,但没有任何反应。

按照我修改清单的 FCM 文档添加:

<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>

是应用配置有问题吗?以我从服务器发送通知的方式?还是只是我使用的插件没有在通知栏中显示任何内容?

...我应该使用收到的数据手动创建通知吗?

【问题讨论】:

  • 尝试重新安装您的应用。或清除数据。
  • 我每次在设备中测试应用程序时都使用命令“ionic run android -c -s”,因此重新安装了应用程序

标签: android angularjs django django-push-notifications cordova-plugin-fcm


【解决方案1】:

可能有两个原因

  1. 您的应用在接收时是否在后台?检查https://firebase.google.com/docs/cloud-messaging/android/receive

  2. 同样基于上述链接,只有在两种情况下,您的设备会自动将您的消息显示为通知。消息可能会传送到您的应用程序,然后您的应用程序需要将通知推送到设备。检查https://developer.android.com/training/notify-user/build-notification.html

【讨论】:

  • 首先,我试图让它与前台的应用程序一起工作。按照您的链接,我将元数据包含在我的清单的应用程序标签中,但没有结果:(
  • @juankysmith 如第一个链接中所述,当您的应用程序处于前台时,消息将直接传递给您扩展 FirebaseMessagingService 的类中的 onMessageReceived() 方法。您已经处理了该消息,并使用第二个链接在您自己的代码中构建了一个通知。换句话说,当使用 FCM 并且应用程序是前台时,将自动显示 NO 通知。您必须对其进行编码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多