【问题标题】:Android notification icon issueAndroid通知图标问题
【发布时间】:2016-10-03 14:52:19
【问题描述】:

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

场景如下:

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

我在 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());

【问题讨论】:

    标签: android push-notification firebase-cloud-messaging


    【解决方案1】:

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

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

    当您希望 FCM 处理显示 代表您的客户端应用程序通知。当您使用数据消息时 想要在您的客户端应用程序上处理消息。

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

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

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

    .

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

    【讨论】:

      【解决方案2】:

      这是 github fcm 页面中详细介绍的 FMC 错误。

      https://github.com/firebase/quickstart-android/issues/4

      【讨论】:

      • 找不到是否已修复。 @seyfx 你有什么线索吗?
      • 你能解释一下“有两种方式发送通知”是什么意思吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-17
      • 2018-10-23
      • 1970-01-01
      • 1970-01-01
      • 2011-08-13
      • 1970-01-01
      • 2017-01-12
      相关资源
      最近更新 更多