我有一个奇怪的问题。我有两种方法可以在我的Android应用中发送通知;一个来自Android服务,另一个来自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());
答案 0 :(得分:3)
您的问题很可能是notification-messages
和data-messages
之间的差异。
请阅读:https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages
当您希望FCM处理显示时,请使用通知消息 代表您的客户端应用程序发送通知。在您使用时使用数据信息 想要处理客户端应用上的消息。
目前,FCM Web控制台仅发送通知消息
因此,通过Web控制台(或通过带有notification
有效负载的API)发送的所有消息都将以这种方式发送:
onMessageReceived()
如果您想要的行为 onMessageReceived()
始终被称为:
然后你需要使用data-only (no notification) message
答案 1 :(得分:-1)
这是github fcm页面中详述的FMC错误。