not get old notification data in android studio

91 views Asked by At

All Mulitple notification display on Mobile screen but when I click on the old notification I got new current notification data. so that I do not get perfect data from the click event. please check what wrong int this code

private void showNotification(Map < String, String > data) {
    String name = data.get("Name").toString();
    String designation = data.get("Designation").toString();
    Intent intent = new Intent(getApplicationContext(), Designation.class);
    intent.putExtra("Name", name);
    intent.putExtra("Designation", designation);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(intent);
    String CHANNEL_ID = "MYCHANNEL";
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        notificationChannel = new NotificationChannel(CHANNEL_ID, "Default channel", NotificationManager.IMPORTANCE_DEFAULT);
        PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), new Random().nextInt(), intent, PendingIntent.FLAG_ONE_SHOT);
        Notification notification = null;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            Uri Emergency_sound_uri = Uri.parse("android.resource://" + getPackageName() + "/raw/push_sound_file");
            Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            notification = new Notification.Builder(getApplicationContext(), CHANNEL_ID)
                .setContentTitle(title)
                .setContentIntent(pendingIntent)
                .setStyle(new Notification.BigTextStyle().bigText(body))
                //   .addAction(android.R.drawable.sym_action_chat,"Title",pendingIntent)
                .setChannelId(CHANNEL_ID)
                .setSmallIcon(R.drawable.notifyicon).setAutoCancel(true)

                .build();

            NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.createNotificationChannel(notificationChannel);
            int id = (int) System.currentTimeMillis();
            notificationManager.notify(id, notification);

            AudioAttributes att = new AudioAttributes.Builder()
                .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
                .build();
            notificationChannel.setSound(Emergency_sound_uri, att);

        }
    } else {}
    notificationChannel.setSound(Settings.System.DEFAULT_NOTIFICATION_URI, audioAttributes);
}

I am trying PendingIntent pendingIntent= PendingIntent.getActivity(getApplicationContext(),1,intent,0); but not working. please give any solution.

0

There are 0 answers