Firebase通知的优先级不高

时间:2017-01-08 00:52:36

标签: android firebase firebase-notifications

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

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

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

1 个答案:

答案 0 :(得分:3)

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

  

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