【发布时间】:2019-07-10 17:54:43
【问题描述】:
我的应用正在使用 firebase 推送通知,通知工作正常。我想做的是像 snapchat 和许多应用程序一样在屏幕上显示通知,但我不知道该怎么做:/
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
showNotification(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody());
}
public void showNotification(String title, String message) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "MyNotifitcation")
.setContentTitle(title)
.setSmallIcon(R.drawable.logo)
.setAutoCancel(true)
.setContentText(message);
NotificationManagerCompat manager = NotificationManagerCompat.from(this);
manager.notify(999, builder.build());
}
【问题讨论】:
-
此方法在您的应用处于前台时触发。所以尝试发送数据通知。这将触发此方法。
标签: android firebase push-notification notifications firebase-cloud-messaging