【发布时间】:2022-01-01 23:29:37
【问题描述】:
伙计们,即使我编写了处理前台的代码,我也只有在后台应用程序时才会收到通知
这是我的 FirebaseMessagingService 类代码:
private static final String CHANNEL_ID ="101" ;
@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
Intent intent = new Intent(this, All_Tickets.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "101")
.setSmallIcon(R.drawable.ic_add)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setContentText(remoteMessage.getNotification().getBody())
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
// Set the intent that will fire when the user taps the notification
.setContentIntent(pendingIntent)
.setAutoCancel(true);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
// notificationId is a unique int for each notification that you must define
notificationManager.notify(1, builder.build());
}
@Override
public void onNewToken(@NonNull String s) {
}
【问题讨论】:
标签: android firebase firebase-cloud-messaging