我有一个奇怪的问题.我有两种方法可以在我的Android应用中发送通知;一个来自Android服务,另一个来自FCM.
方案如下:
>无论应用程序是否正在运行,Android服务发送的通知图标都会正确显示.
>当应用程序运行时,如果我通过FCM发送通知,则仍会正确显示通知图标.
>但是如果应用程序没有运行并且我通过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());