Android通知图标问题

时间:2016-06-03 13:44:40

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

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

方案如下:

  1. 无论应用程序是否正在运行,Android服务发送的通知图标都会正确显示。
  2. 当应用程序运行时,如果我通过FCM发送通知,则通知图标仍然会正确显示。
  3. 但如果应用未运行且我通过FCM发送通知,则会显示白色方块而不是通知图标。
  4. 我在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());
    

2 个答案:

答案 0 :(得分:3)

您的问题很可能是notification-messagesdata-messages之间的差异。

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

  

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

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

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

  1. 如果应用已关闭或在后台:FCM将显示通知。如果您想自定义它,但您需要提供特定配置(在清单或send API调用中),请参阅https://firebase.google.com/docs/cloud-messaging/android/client#manifest
  2. 如果应用处于前台:FCM将调用onMessageReceived()
  3. 如果您想要的行为 onMessageReceived() 始终被称为
     然后你需要使用data-only (no notification) message

答案 1 :(得分:-1)

这是github fcm页面中详述的FMC错误。

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

相关问题