gpt4 book ai didi

安卓通知图标问题

转载 作者:搜寻专家 更新时间:2023-11-01 09:47:04 26 4
gpt4 key购买 nike

我有一个奇怪的问题。我有两种方式在我的 Android 应用程序中发送通知;一个来自 Android 服务,另一个来自 FCM。

场景如下:

  1. 无论应用是否正在运行,Android 服务发送的通知图标都会正确显示。
  2. 当应用程序运行时,如果我通过 FCM 发送通知,通知图标仍会正确显示。
  3. 但如果该应用未运行并且我通过 FCM 发送通知,则会显示一个白色方 block 而不是通知图标。

我在 FCMService 中的代码:

Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("Android App")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());

最佳答案

您的问题很可能是 notification-messagesdata-messages 之间的区别。

请阅读:https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages

Use notification messages when you want FCM to handle displaying a notification on your client app's behalf. Use data messages when you want to process the messages on your client app.

目前 FCM Web 控制台仅发送通知消息

因此,所有通过 Web 控制台(或通过带有 notification 负载的 API)发送的消息都将以这种方式发送:

  1. 如果应用已关闭或处于后台:FCM 将显示通知。如果你想定制它你可以,但你需要提供特定的配置(在 list 或发送 API 调用中)参见 https://firebase.google.com/docs/cloud-messaging/android/client#manifest
  2. 如果应用在前台:FCM 将调用 onMessageReceived()

.

如果您想要的行为是 onMessageReceived() 总是调用:
那么你需要使用一个data-only (no notification) message

关于安卓通知图标问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37616065/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com