【发布时间】:2020-08-21 06:06:44
【问题描述】:
我正在使用 Firebase 生成通知,假设有 3 个通知,如果用户点击任何一个所有通知都消失了,我需要的是,当用户点击一个通知时,其他 2 个应该在通知中我已经完成了我的代码。
Intent intent;
if (pref.getString("id","").equals("")){
intent = new Intent(this, Login_Activity.class);
}else {
intent = new Intent(this, TicketListActivity.class);
}
// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_ONE_SHOT);
String channelId = "Default";
String msgBody = remoteMessage.getData().get("body");
String ticketid = remoteMessage.getData().get("ticket_Id");
Notification notification = new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.app_launch)
.setContentTitle(remoteMessage.getData().get("title"))
.setContentText(remoteMessage.getData().get("body")).setAutoCancel(true).setContentIntent(pendingIntent)
.setStyle(new NotificationCompat.BigTextStyle().bigText(remoteMessage.getData().get("body")))
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setOngoing(true)
.build();
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId, "Default channel", NotificationManager.IMPORTANCE_DEFAULT);
manager.createNotificationChannel(channel);
}
// manager.notify((int) ((new Date().getTime() / 1000L) % Integer.MAX_VALUE), notification);
manager.notify((int) System.currentTimeMillis(), notification);
【问题讨论】:
标签: android android-studio push-notification android-notifications