Notifications
Notifications
Khan Institute of
Computer Sciences and
Information Technology Kahuta
Android App Development
ASSIGNMENT
Submitted by:
Syed Mazhar Hussain Shah
(222201011)
BSCS-6
Inbox Notification:
Explanation: Inbox-style notifications display multiple messages within a
single notificationThe InboxStyle allows displaying multiple lines within a
notification, useful for inbox or chat-like notifications..
Code Snippet: NotificationCompat.InboxStyle inboxStyle = new
NotificationCompat.InboxStyle() .setBigContentTitle("Inbox
Messages") .addLine("Ali: Hello!") .addLine("Sara: Assignment
done?") .addLine("John: Meeting at 3 PM") .addLine("Hina: Call me
ASAP") .addLine("Zain: Check email");
NotificationCompat.Builder builder = new NotificationCompat.Builder(this,
CHANNEL_ID) .setSmallIcon(android.R.drawable.ic_dialog_email) .setContentT
itle("Inbox Notification") .setContentText("You have 5 new
messages") .setStyle(inboxStyle) .setPriority(NotificationCompat.PRIORITY_D
EFAULT);
Output
Call Notification:
Explanation: Call notifications allow the user to either accept or decline an
incoming call from the notification itself.This code implements a call
notification with actions to accept or decline the call.
Code Snippet: Intent acceptIntent = new Intent(this, MainActivity.class); //
Dummy intent PendingIntent acceptPendingIntent =
PendingIntent.getActivity(this, 0, acceptIntent,
PendingIntent.FLAG_IMMUTABLE);
Intent declineIntent = new Intent(this, MainActivity.class); PendingIntent
declinePendingIntent = PendingIntent.getActivity(this, 1, declineIntent,
PendingIntent.FLAG_IMMUTABLE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this,
CHANNEL_ID) .setSmallIcon(android.R.drawable.sym_call_incoming) .setCont
entTitle("Incoming Call") .setContentText("Zain is
calling...") .setPriority(NotificationCompat.PRIORITY_HIGH) .setCategory(Noti
ficationCompat.CATEGORY_CALL) .addAction(android.R.drawable.sym_action_
call, "Accept",
acceptPendingIntent) .addAction(android.R.drawable.ic_menu_close_clear_ca
ncel, "Decline",
declinePendingIntent) .setAutoCancel(true) .setFullScreenIntent(acceptPendi
ngIntent, true);
Output
Message Notification:
Explanation: Message notifications use the MessagingStyle to display a
conversation with multiple messages The MessagingStyle creates a message
thread, useful for chat-style notifications..
Output