安卓工作室通知显示错误



我正在开发一个应用程序,该应用程序接收来自Firebase的通知。当我收到它们时,它没有正确显示它们。当我尝试更改图标时,它仍然显示启动器图标。此外,灯光和振动不起作用,收件箱样式也不起作用,它只是显示另一个通知。我尝试了NotificationCompat.Builder和Notification.Builder,但它仍然不起作用。我用于显示通知的代码:

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);        
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());
builder.setLights(Color.BLUE, 2000, 2000)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(remoteMessage.getData().get("username"))
.setContentText(remoteMessage.getNotification().getBody())
.setVibrate(new long[]{0,500,0,500})
.setWhen(remoteMessage.getSentTime())
.setAutoCancel(true)
.setStyle(styles)
.setPriority(Notification.PRIORITY_HIGH)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setContentIntent(pendingIntent);
notificationManager.notify(NOTIFICATION_ID, builder.build());

Firebase 是否有可能覆盖我的通知,或者这是不可能的?

好的。我找到了我的问题。我通过 Firebase Cloud Functions 收到通知。但是我试图展示该方法的方法( onMessageRecieved (仅在应用程序位于前台时才有效。所以我搜索了一下,发现我必须覆盖handleIntent(Intent intent)方法,当应用程序在后台时也可以工作。我不得不在Firebase云功能的代码中进行一些更改(将相关数据添加到通知中的数据部分(,然后我就可以从Intent接收数据intent.getStringExtra("String").现在它工作正常。

相关内容

最新更新