Notification
Prasanna Kumar K R
AP/IT
Notification
Set the notification content�
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)� .setSmallIcon(R.drawable.notification_icon)� .setContentTitle(textTitle)� .setContentText(textContent)� .setPriority(NotificationCompat.PRIORITY_DEFAULT);�
Set the notification's tap action
Intent intent = new Intent(this, AlertDetails.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, CHANNEL_ID)� .setSmallIcon(R.drawable.notification_icon)� .setContentTitle("My notification")� .setContentText("Hello World!")� .setPriority(NotificationCompat.PRIORITY_DEFAULT)� // Set the intent that will fire when the user taps the notification� .setContentIntent(pendingIntent)� .setAutoCancel(true);�
Show the notification
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);��// notificationId is a unique int for each notification that you must define�notificationManager.notify(notificationId, builder.build());�