Firebase通知未发送为高优先级

编程入门 行业动态 更新时间:2024-10-25 12:18:37
本文介绍了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通知未发送为高优先级

本文发布于:2023-11-16 23:08:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607873.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:优先级   通知   Firebase

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!