首先,您应该在通知中具有特定的有效负载,在您的情况下,它应该是特定聊天的ID,然后您可以使用该ID来执行您想要做的操作,使用此代码
type = remoteMessage.getData().get("type");
if(type.equals("1")) {
Intent intent;
PendingIntent pendingIntent;
NotificationCompat.Builder builder;
if (notifManager == null) {
notifManager = (NotificationManager) getSystemService
(Context.NOTIFICATION_SERVICE);
}
intent = new Intent (this, Admin_page.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_HIGH;
if (mChannel == null) {
NotificationChannel mChannel = new NotificationChannel
("0", title, importance);
mChannel.setDescription (body);
mChannel.enableVibration (true);
mChannel.setVibrationPattern (new long[]
{100, 200, 300, 400, 500, 400, 300, 200, 400});
notifManager.createNotificationChannel (mChannel);
}
builder = new NotificationCompat.Builder (this, "0");
intent.setFlags (Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
pendingIntent = PendingIntent.getActivity (this, 0, intent, 0);
builder.setContentTitle (title)
.setSmallIcon(R.drawable.logo_app).setTicker(title).setWhen(0)
.setContentText (body)
.setDefaults (Notification.DEFAULT_ALL)
.setAutoCancel (true)
.setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.logo_app))
.setContentIntent (pendingIntent)
.setSound (RingtoneManager.getDefaultUri
(RingtoneManager.TYPE_NOTIFICATION))
.setVibrate (new long[]{100, 200, 300, 400,
500, 400, 300, 200, 400});
} else {
builder = new NotificationCompat.Builder (this);
intent.setFlags (Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
pendingIntent = PendingIntent.getActivity (this, 0, intent, 0);
builder.setContentTitle (title)
.setSmallIcon(R.drawable.logo_app).setTicker(title).setWhen(0)
.setContentText (body)
.setDefaults (Notification.DEFAULT_ALL)
.setAutoCancel (true)
.setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.logo_app))
.setContentIntent (pendingIntent)
.setSound (RingtoneManager.getDefaultUri
(RingtoneManager.TYPE_NOTIFICATION))
.setVibrate (new long[]{100, 200, 300, 400, 500,
400, 300, 200, 400})
.setPriority (Notification.PRIORITY_HIGH);
}
Notification notification = builder.build ();
notifManager.notify((int)date.getTime(), notification);
}
希望对你有帮助