Firebase通知未发送为高优先级 [英] Firebase notifications are not sending as high priority

查看:83
本文介绍了Firebase通知未发送为高优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我通过Firebase Web界面向我的Android设备发送通知时,该通知不会从状态栏中显示下来.如果我想查看通知,则必须向下滑动.即使在Web界面中将优先级设置为 High 时,也会发生这种情况.为什么会这样?

When I send a notification to my Android device through the Firebase web interface, the notification doesn't peek down from the status bar. If I want to see the notification, I must swipe down. This occurs even when I have the priority set to High in the web interface. Why is this?

如果在打开应用程序时通知到达,这不是问题,因为我可以在我的 FirebaseMessagingService 类中自行设置优先级:

This is not an issue if the notification arrives when the app is open because I can set the priority myself in my FirebaseMessagingService class:

public class MyFirebaseMessagingService extends FirebaseMessagingService {

  @Override public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);
    sendNotification("Message Body");

  }

  /**
   * Create and show a simple notification containing the received FCM message.
   *
   * @param messageBody FCM message body received.
   */
  private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, SubscribedActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
        PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.ic_push_notification)
        .setContentTitle("FCM Message")
        .setContentText(messageBody)
        .setAutoCancel(true)
        .setSound(defaultSoundUri)
        .setPriority(NotificationCompat.PRIORITY_MAX)
        .setColor(ContextCompat.getColor(this, R.color.color_accent))
        .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
  }
}

推荐答案

打开应用程序时,您正在处理自己的通知,因此可以控制它的操作.但是,当应用程序在后台运行时,通知是由系统任务栏处理的,并且您可以从Web控制台传递的唯一优先级参数是正常的.但是,如果用户不与您的应用进行交互,则通过较高的信誉将无法按预期进行.文档

When the app is open, you are handling your own notification and therefore you can control what it does. However, when the app is in background, the notification is handled by system tray and the only priority paramaters you can pass from the web console are high and normal. Passing the prority as high however will not work as intended if the users don't interact with your app. Documentation

高优先级消息通常应导致用户与您的应用进行交互.如果FCM检测到没有这种模式,则您的邮件可能会被取消优先级.

High priority messages generally should result in user interaction with your app. If FCM detects a pattern in which they don't, your messages may be de-prioritized.

这篇关于Firebase通知未发送为高优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆