gpt4 book ai didi

android - 多个通知点击启动相同的 Activity android

转载 作者:行者123 更新时间:2023-12-05 00:11:24 28 4
gpt4 key购买 nike

我设置了通知:

private void sendNotificationForCancellation(String appointmentId, String title, String message) {
//AppController.getSharedPreferences().edit().putString(Constants.CALL_CASE_ID, notifObject.getCaseDetails().getCaseID()).commit();
Intent intent = new Intent(this, ActCallRequestsDetail.class);
intent.putExtra("appointment_id", appointmentId);
intent.putExtra("isAppIdAvailable", true);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_note_plus)
.setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.app_icon))
.setContentTitle(title)
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);

NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

Random generator = new Random();
notificationManager.notify(generator.nextInt(), notificationBuilder.build());
}

点击通知它会打开一个 Activity

场景 1:

  • 当我收到一条通知时它工作正常。

.场景 2:

  • 假设首先从上述通知设置生成 2 个通知通知点击,它正在打开 Activity 现在我在打开 Activity (ActCallRequestsDetail.class) 当我点击第二次通知, Activity 没有任何反应(ActCallRequestsDetail.class) 未刷新

.如何解决场景 2

最佳答案

解决方案只是为 PendingIntent 引用添加一个新 ID

private void sendNotificationForCancellation(String appointmentId, String title, String message) {
Random generator = new Random();
//AppController.getSharedPreferences().edit().putString(Constants.CALL_CASE_ID, notifObject.getCaseDetails().getCaseID()).commit();
Intent intent = new Intent(this, ActCallRequestsDetail.class);
intent.putExtra("appointment_id", appointmentId);
intent.putExtra("isAppIdAvailable", true);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

PendingIntent pendingIntent = PendingIntent.getActivity(this, generator.nextInt(), intent, PendingIntent.FLAG_ONE_SHOT);

Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_note_plus)
.setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.app_icon))
.setContentTitle(title)
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);

NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);


notificationManager.notify(generator.nextInt(), notificationBuilder.build());
}

关于android - 多个通知点击启动相同的 Activity android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40174156/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com