当我通过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通知未发送为高优先级
发布评论